Setting up reference to an inactive GameObject through script

Is this not allowed? I have tried setting up a reference to an inactive GameObject through script using the Awake() method. Unfortunately, I always end up with null. I know that it would work if I set up the references using the UnityEditor properties by dragging but I would prefer setting them up using a script in cases of having the reference holder being non-existent yet (Instantiating during run time).

OK, so instead of setting that when gameObjectA is instantiated why not do this…

Make gameObjectB a prefab and instantiate it when needed, from the script that instantiates it hold a reference to ScriptA and have a public function in ScriptA to pickup gameObjectB and when you instantiate gameObjectB call that function just afterwards.

It should pick up the newly instantiated object once it’s there.

Do you need help with the scripting and if yes javascript or C#?