- Home /
How do I assign a prefab to a variable with a script?
I have variable whose prefab keeps changing to none each time i start the game. How do I set the prefab through the script?
Comment
What does "variable whose prefab keeps changing to none each time i start the game" mean?
If you don't provide any script, how the community is supposed to help ?
Sounds a lot like you're trying to fix a problem that you shouldn't have in the first place. If you have a reference you've assigned a prefab to, why would it reset on Start? There must be some reinitialisation somewhere. What is your reference/variable like ?
Answer by Piyush_Pandey · Jul 20, 2017 at 12:43 PM
what i can understand from the question can be done as:-
void Start()
{
GameObject your_variable = Resources.Load(".. file path in resource") as GameObject;
}
I am not sure if you are using a GameObject or Mesh or whatever type. Use it accordingly
Your answer
![](https://koobas.hobune.stream/wayback/20220612130649im_/https://answers.unity.com/themes/thub/images/avi.jpg)