- Home /
Problem is not reproducible or outdated
C# event setup, no result
Class one on Skellie has:
public delegate void MobPulled();
public event MobPulled mobPulled;
Class two on Skellie has:
void OnEnable() {
one.mobPulled += PlayParticles;
}
void PlayParticles() {
particles.Play ()
Class one has method
...
Debug.Log("Publishing...");
if (mobPulled != null) {
Debug.Log ("...Event published");
mobPulled (); }
...
Publishing shows up, Event published does not (so subscribers is null?) and the particles don't play - what have I missed?
I had a gameoject in the Prefab hierarchy accidentally disabled. Once I enabled that on the prefab, this all worked fine.
$$anonymous$$eep in $$anonymous$$d that if your item gets enable/disable many times, you are registering an extra method each time.
So you will see PlayParticles being called 1,2,3 or more times since each enabling registers the method.
You would need to remove the listener on disable and on destroy. The second will prevent a NRE since the event would call a method on an object that does not exist anymore.