Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug GetInstanceID() isn't alwasy correct

Discussion in 'Editor & General Support' started by ByteRockersGames, Mar 11, 2023.

  1. ByteRockersGames

    ByteRockersGames

    Joined:
    Dec 20, 2012
    Posts:
    5
    When an GameObject(Prefab) gets instanced from a scene file the instance id is positive. This can be reproduced by building a version with IL2CPP. After build is done start the editor again and the ID is > 0. I expected to be < 0.

    here an easy test script on to receive an asset

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class InstanceCheck : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         Debug.Assert(GetInstanceID() < 0, "GameObject isn't an instance"); // but isn't prefab, too
    8.     }
    9. }
    10.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    And why do you expect this?

    The documentation seems fairly clear and it is trivially easy to experiment with.
     
  3. ByteRockersGames

    ByteRockersGames

    Joined:
    Dec 20, 2012
    Posts:
    5
    A Prefab instantiated from scene file is an instance, right? so InstanceID should be < 0.

    Source: https://docs.unity3d.com/ScriptReference/Object.GetInstanceID.html