How can i get a script of a non instantiate prefab?


I need change the values of a prefab before instantiate it. It’s possible or i need to save N prefab with different values each one?

Because the prefab its the same, but i want modify his mass of rigidbody to create different gravities for each instantiate;


C#, Unity 2017.1.0f3

The values of each prafabs will mantain in each instantiating.
So, I dont see a problem if you change it after intantiated, but if you want to do what you say, you need a reference of prefeab in the script, like drag and drop in the inspector, and change the values that you mention and then instantiate that prefab. I dont so sure about the last solution.

You can’t modify a Prefab’s values at runtime.

I guess you’re getting those values from Awake or Start method.

You could call a custom “Init” method on your instantiated objects after instantiation.

To be honest, you’ll probably have to rewrite part of your code. While you’re at it, you could add some Object Pooling.
This will lead you to adding custom Init (or OnEnable) initialisation.