- Home /
Checking to see if a Public transform is (missing)
Hello everyone, I have 2 prefabs (prefab1 and prefab2); prefab1 has a script which checks prefab2's transform realtime when it spawns. However, When I delete prefab2; I need the script in prefab one to check to see if prefab2 transform is deleted (missing). I tried this:
public Transform prefab2;
void Update(); { if(prefab2 != null){ //what the script does if prefab2 is missing; }
}
But it did not work, Here is my error:
Your script should either check if it is null or you should not destroy the object. How can you check to see if a public transform is missing? (c#) - (In the inspector its seen as "Transform (Missing)") Thanks!MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
Answer by fafase · Mar 17, 2013 at 09:19 PM
You could use a try/catch which would return the state but avoid the exception
try{
if(prefab2){
// prefab2 is
}
}catch(Exception){
// No prefab2
}
Your answer
Follow this Question
Related Questions
How to unparent a Transform by UnityEvent? 1 Answer
why a list of transforms is empty after loading new scene? 2 Answers
update function problem 2 Answers
MissingReferenceException Help 1 Answer