- Home /
Instantiate a prefab in every scene
Guys,
I am looking for a way to instantiate a prefab in every scene without neither putting gameobjects of it in editor nor another gameobject calling the instantiate. Any idea?
The moral: I have a "Cheater" to test my game easily. I want to have it when I want to test the scenes individually via pressing run on a scene.
Answer by ErayT · Jan 30, 2018 at 07:33 AM
I have accomplished this by having a method with the attribute [RuntimeInitializeOnLoadMethod ]. This helped me to trigger a method without having a script inside any scene and then Instantiated the prefab that I want with DontDestroyOnLoad
Answer by Trickman · Jan 29, 2018 at 03:27 PM
Get it by making sure it's in the "Resources" folder, and then using:
GameObject myObject = (GameObject) Resources.Load("<path>");
Here is some info and examples about how to use it: https://docs.unity3d.com/ScriptReference/Resources.Load.html
Happy coding!
Thanks for the answer. However, there must be another script attached, at every scene to run that script. This is not I want and something that I avoid.