Search Unity

GetInstanceId() behavior on different platforms - need dev confirmation.

Discussion in 'Editor & General Support' started by delstrega, Jun 23, 2012.

  1. delstrega

    delstrega

    Joined:
    Apr 22, 2012
    Posts:
    14
    I stumbled across something interesting trying to get rid of "Destroying assets is not permitted to avoid data loss." errors.

    Since I couldn't use AssetDatabase.Contains() at runtime to check if a given material is an asset or not, I searched for other ways to distinguish. That's when I discovered that GetInstanceId() returns a negative value for materials that were created using "= new Material(...)" and positive values for materials that were in fact assets.

    That's why I need confirmation from the Unity devs:

    Is this intended behavior? Is it safe to assume that GetInstanceId() will return negative values on every platform for code created materials? Might this change in the future?

    Thanks in advance,

    delstrega
     
    Last edited: Jun 23, 2012
  2. Tct1856

    Tct1856

    Joined:
    Jan 22, 2010
    Posts:
    104
    Hi,

    yes, this is intended behaviour, and yes the same behaviour is on other platforms aswell.

    I very doubt it, as this is in the very core of the code. But you never know :)
     
  3. delstrega

    delstrega

    Joined:
    Apr 22, 2012
    Posts:
    14
    Great! This makes eliminating leaks sooo much easier ;D Thanks Tct!