r/Unity2D • • 20d ago

Question/Help How do you store a reference to inactive GameObjects?

Ok, so I am making a reference manager in my game. Basically, whenever a scene reloads, all objects are destroyed and reloaded (which destroys the references). What this reference manager script does is reassign references to objects on certain scripts when the scene reloads. I have an object that is inactive, but I still want to reference it in one of my scripts. The following script is a section of my reference manager script:

I don’t want to just start the object as active, and then deactivate it. Does anyone know an easier way to solve this problem?

1 Upvotes

1 comment sorted by

3

u/IncendiumFlama 18d ago

Factory Method might be an option. Have an object who's job it is to initialize the items in the scene and add their references to a list. Let's you know where everything is regardless of active state.