- Home /
Question by
richielyl · Jul 08, 2017 at 07:37 PM ·
prefabnullreferenceexceptiongenerationgenerator
Null reference for variables(prefabs) when referencing another script
I have a script (structure_gen) in my main camera and another script in another gameobject(building_generator). They are on the same level. The script in the main camera is able to get the script in the building_generator but it's saying the prefabs that I dragged into the building_generator script to be null, and I have no idea why. Please help....
//In Structure_gen script calling building generator
void Start()
{
Debug.Log(gameObject.name);
GameObject building_generator_holder = GameObject.FindGameObjectsWithTag("Generator")[0];
b_generator = building_generator_holder.GetComponent<building_generator>();
b_generator.init_prefabs();
}
//In building_generator script - Prefabs
public Transform stair1;
public Transform stair2;
public Transform stair3;
//.......
void init_prefabs()
{
prefabs[1] = stair1;
prefabs[2] = stair2;
prefabs[3] = stair3;
//........
}
qa-sc2.png
(27.1 kB)
qa-sc1.png
(38.6 kB)
Comment
Your answer
Follow this Question
Related Questions
Help how to reference prefab for instantiating between loads. 0 Answers
Referencing gameObject from script after Instantiate 0 Answers
NullReferenceException from a script after linking prefab with drag and drop in inspector. WTF? 1 Answer
Prefab Random Generation 0 Answers
NullReferenceException when trying to programatically populate cubes 0 Answers