I’ve been trying to tidy up my code in a game I’m working on and I’m having difficulty figuring out the best way to do this cleanly. I have instantiated prefabs with scripts that need references to a Transform in the scene.
I’m trying to avoid using a singleton, but I’m not sure how else to get a reference to this particular GameObject in the scene, from the script that runs on the prefab when it is instantiated. I could do something like finding the GameObject by name, but that seems quite inefficient when it would be doing that every time a new instance is created, and that would be fairly frequently.
What’s the best practice for a script that lives on a prefab getting a reference to a GameObject in the scene?