Repeat an OnParticleCollision event

Hello everyone! I’ve got a specific example I haven’t seen answered yet. I’m setting up a system of nodes in my game which begin in an unpowered state, with the objective of making a network of nodes reach a target (e.g. Connect the dots). Nodes can become disconnected from the network by other player actions, so they need to turn off automatically after a particle collision event and delay; but if they are reconnected they need to turn back on.

So far I haven’t been able to make the OnParticleCollision() system reactivate when hit by the same particle system and I’m not sure what I’m missing.

// On a particle collision with particle
    //This only fires once
    void OnParticleCollision()
    {
        //This section is on
        Debug.Log("Particle Collision");

        //When collision, set networked(Powered) to true
        networked = true;
        Debug.Log("Node Online");

        //Delay for 3 secs, then set networked to false
       //Code goes here to delay. networked = false
        Debug.Log("Node Offline");

        //Begin activation of another section with processed code..
        ReactToHit(code);
    }
    IEnumerator Delay()
    {
        yield return new WaitForSecondsRealtime(3);
    }

Line 14 executes instantly, then moves onto networked = false; and so on.

Meanwhile, three seconds later Delay() finishes and nobody is the wiser.

To get what you want, you can probably move the entire contents of your OnParticleCollision() function into a coroutine, then just start it from OnParticleCollision().

Once it’s all in a coroutine, instead of saying Startcoroutine(Delay(), just actually DO the yield return new WaitForSeconds right there in line.

So far, the delay is not an issue, it’s only there for completeness/sketching. What really matters is that I can get OnParticleCollision to refire…

OK, but:

//Delay for 3 secs, then set networked to false
        StartCoroutine(Delay());
        networked = false;
        Debug.Log("Node Offline");

It doesn’t work that way. This won’t “delay for 3 secs, then set networked to false”. This fires off the coroutine, then immediately sets networked to false without waiting for the coroutine to finish.

As for why OnParticleCollision isn’t firing again… is it possible that the colliders are still disabled? You mentioned that nodes are disabled then turned back on. It seems like something still isn’t being turned back on properly.

Do you get a collision if you try a different particle system? Does the particle system still work with other nodes (that haven’t been disabled yet)? Adding more Debug.Log everywhere can help narrow this down.aaa

Issue resolved itself, it may have been improper execution steps before the particle collision event.