Referencing Inactive Objects.

Object A(has a script, hundred of instances)
Object B(Just 1 object)

All instances of A needs to reference object B.
Object B needs to be inactive when the game starts or before its used.

I wont assign references through the inspector because of the amount of instances. I have tried prefabs, they dont work.

Object A cant reference object B when its inactive using GameObject.Find, it has to be referenced before its inactive.

What method could use to solve this?

A method to return all instances of the script then check if all instances have referenced B?

Use a method that can reference inactive objects?

You can use Transform.Find() if the object B is child to something active. This will find any object inside of a certain object’s transform including the inactive GameObjects. Unity - Scripting API: Transform.Find

If B is not child to anything, you could also put it active on default, and in A’s Start function :

  • Reference B to it
  • Disable the object after

thanks ^^