- Home /
GameObject not found by [InitializeOnLoad] class
At startup of the editor, I have a class with tag [InitializeOnLoad] which has a constructer wherein it looks for a GameObject by name in the scene.
It consistently is unable to find said GameObject, however has no trouble finding it on a recompile or start play mode.
Question: 1) Please explain why it can't find the GameObject? I assume it has something to do with InitializeOnLoad being called at startup before the scene is loaded (which seems kinda silly tbh) 2) Is there another way to find a GameObject at the startup of the editor?
Edit: Actually it doesn't look for a GameObject but for a class. This is the code called at InitializedOnLoad and always fails even though it works on a later reload just fine
SceneManager sceneManager = (SceneManager)SceneManager.FindObjectOfType(typeof(SceneManager));
Have you tried the singleton pattern, as suggested by the docs?
Your answer
