- Home /
Particle Emitter error, Missing reference exception.
Hi, I have a this error constantly popping up.
MissingReferenceException: The object of type 'ParticleEmitter' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
I have this script on my waterfall, the tag "EditorOnly" is a rock object (with a mesh collider) designed to stop the waterfall from flowing when it conjuction with the waterfalls collider. All the publicemitters are assigned in the inspector. thanks.
using UnityEngine;
using System.Collections;
public class Waterfalltrigger2 : MonoBehaviour {
public ParticleEmitter myBigmist = null;
public ParticleEmitter myEmitter = null; public ParticleEmitter myWatersplash = null;
public Light Waterpointlight = null;
void OnTriggerEnter(Collider other){ if(other.CompareTag("EditorOnly")) myEmitter.emit = false ; myWatersplash.emit = false ; myBigmist.emit = false ; Waterpointlight.intensity = 0 ; }
void OnTriggerExit(Collider other){ if(other.CompareTag("EditorOnly")) myEmitter.emit = true ; myWatersplash.emit = true ; myBigmist.emit = true ; Waterpointlight.intensity = 2 ; } }
Answer by rutter · Jun 07, 2012 at 07:16 AM
I would try hijinxbassist's suggestion.
If that doesn't work, make sure that you've set the references up in the inspector. If any of them are listed as "None", they're not pointing at anything.
Finally, you might want to check if the ParticleEmitter has AutoDestruct
set -- if so, it will self-destroy once the emitter has finished. After that happens, subsequent attempts to access to emitter can produce errors.
If push comes to shove, you could always check for null
before using the reference. It might allow you to figure out exactly when things are going wrong, if you log a message once that happens.
i tried hijinx's method, didnt work but then i turned off the automatic emit on the waterfall and it worked for some reason. i did leave =null out by the way
thanks for the help guys.
Your answer
Follow this Question
Related Questions
Casting error on multiple emitters 3 Answers
What is happening and what does this MEAN!?!?!?!?!?!?!?!? AHHHHH!!!!,WHAT IS HAPPENING?!?! 1 Answer
Too many errors in the IDE (even for a fresh project), but editor doesn't throw any errors! 1 Answer
GameManager trying to access method from deleted GameManager via the InvokeRepeating() function 0 Answers