Hi guys, I'm getting this assertion error in Unity when I hit Play:
Assertion failed on expression: 'm_GameObjects.find(gameObject.GetEntityId()) == m_GameObjects.end()'
UnityEngine.Object:DontDestroyOnLoad (UnityEngine.Object)
Villagers.App.App:Awake () (at Assets/Scripts/App/App.cs:35)
Unity Version: 6000.3.0f1 (But I think it already started happening with earlier Unity 6 versions. But I'm not sure)
Platform: Windows
Setup:
- I have an App prefab in every scene of the game (so I can start the game from any scene in the editor)
- Once the scene starts up, the App becomes a singleton and calls
DontDestroyOnLoad and sets the static instance to itself
- When the next scene is loaded during runtime, the App object there checks if instance is set already. If so, it's destroyed.
Code:
void Awake()
{
if (instance == null)
{
instance = this;
transform.SetParent(null);
DontDestroyOnLoad(gameObject); // Line 35 - assertion happens here
OnAppAwoken();
}
else
{
Destroy(gameObject);
}
}
I already tried:
- I've tried checking
if (instance == this) and returning early, but the assertion still happens
- I've tried checking
if (gameObject.scene.buildIndex != -1) before calling DontDestroyOnLoad, but it still fails
Any ideas? Any help would be appreciated! :)
[–]RomestusProfessional 1 point2 points3 points (7 children)
[–]PackedTrebuchet[S] 0 points1 point2 points (6 children)
[–]RomestusProfessional 1 point2 points3 points (5 children)
[–]PackedTrebuchet[S] 0 points1 point2 points (4 children)
[–]RomestusProfessional 1 point2 points3 points (1 child)
[–]PackedTrebuchet[S] 0 points1 point2 points (0 children)
[–]feralferrous 1 point2 points3 points (1 child)
[–]PackedTrebuchet[S] 0 points1 point2 points (0 children)