missing gameObject reference, plz help

hi,
my problem is that I have multiple objects/ scripts referencing one object, and when that object is destroyed, (this gets a little confusing) the killer continues working perfectly but the others receive a “missing (game object”) in there target variable and stop working.

I’ve read through about 50 pages of forum posts trying to find something that might solve my problem but no luck. Is there a way to say:

If(gameObject == missing){
doSomething;
}

Thanks in advance for any help or suggestions.

if(gameObject == null) {
  doSomething;
}

:slight_smile:

although you probably want something more along these lines:

if (targetGameObject != null) {
  do something...
} else {
  pick a new target...
}

hope this helps.

hi, thanks for your reply, i have tried this and it doesnt work. it still shows in the inspector that Target = Missing(GameObject)

im tring a different approach at the moment, in which when a object runs out of health a boolean is set to true which triggers pickNewTarget, and then removes the object.

Use “gameObject.activeSelf” instead.

if the Object is missing, activeSelf==false

1 Like