- Home /
Tagging a prefab breaks my code?
This is a class I am using. SendActivity() is called when the player performs an action. It finds any objects in the scenes tagged as "Receiver", stores that as a temporary array and then sets a bool to true in each of those objects.
This was working exactly as intended for the longest time, until I created a new prefab. I changed nothing in this code or any related code, all I did was add a prefab and tagged it as "Receiver". Previously, I had two Prefabs tagged as such. This new prefab and the existing ones have the ActivityReceiver script attached. Now, whenever SendActivity() is called at all, it throws a Null Reference Exception. The prefab that was added isn't even instantiated in the scene. If I delete the prefab or change its tag back to Untagged, everything works again.
I am dumbfounded here, help please!?
GameObject[] receivers;
void FindReceivers(){
receivers = GameObject.FindGameObjectsWithTag("Receiver");
}
public void SendActivity(){
FindReceivers();
for(int x=0; x<receivers.Length; x++){
receivers[x].GetComponent<ActivityReceiver>().activityReceived = true;
}
}
Your answer
Follow this Question
Related Questions
Prefab tag bug 0 Answers
Can't get more than one object. 1 Answer
A limit to the number of tags? 2 Answers
I discovered special Tag tricks, what are the rest of the commands? 0 Answers
I cant change tag on two objects simultaneously? Why? 1 Answer