0 like 0 dislike
548 views
I have an int atribute with min 0 and max 0 values. I want it to trigger an event.

SpawnParticlesEvent.trigger(AttributeA == 0);

This works, but the particles spawn every frame instead of just once.

I can't change the event mode to TriggerOnce, it's greyed out.

Is there a way to change it through the script or some other...alternative way
asked by Zheljka (720 points)

2 Answers

0 like 0 dislike
 
Best answer
If you want only 1 trigger for the whole effect, whatever the number of particles, you can create another Layer, non-Infinite, Duration=0, SpawnCountMode=TotalParticleCount, SpawnCount=1, so this layer will spawn only 1 particles, then do your trigger inside the Spawner Script.
answered by Jordan (14.6k points)
Note, if you trigger inside the Spawner Script, make sure you trigger inside the "PostEval()" function (executed in world space, "Eval()" is local space):

function void Eval()
{
// ....
}
function void    PostEval()
{
    MyEvent.trigger(true);
}
I made a "dummy" layer so I could have it trigger a whole effect at once, and it worked well.Thank you...

However,
The event  triggers once but only on frame one (When I push the rest particle system for example). If I Turn on the AttributeA to 1 and then back to 0 again it won't respond.
I need it to trigger an event once every time the AttributeA is set to 0.
Is that possible?
With a mix of the two solutions, you should be able to do that:

Create the 1 particle Layer, then instead of trigger in Spawner Script, create a "int" "Triggered" particle field and a Script Evolver containing:

int  doTrigger = (AttributeA == 0 && Triggered == false);
SpawnParticlesEvent.trigger(doTrigger);
Triggered = doTrigger; // so it wont trigger next frame
Note:
This will trigger only the first time AttributeA == 0 and then nerver trigger again.
Your particle Life must be great enough so that the particle will not die before the you change AttributeA.
ERRATUM:

To spawn once, every time you set AttributeA to 0:

int  doTrigger = (AttributeA == 0 && Triggered == false);
SpawnParticlesEvent.trigger(doTrigger);
Triggered = Triggered || doTrigger; // don't spawn next frame
Triggered = iif(AttributeA != 0, false, Triggered); // reset if AttributeA != 0, else keep last value
It's working now.
Thank you so much. I very much appreciate your help.

P.S. For anyone else reading this post, I've also put LifeRatio = 0; to the Evolver Script. That way the "dummy particle" is always living.
1 like 0 dislike

You could add a particle field "int" called "Triggered", then in your script:

SpawnParticlesEvent.trigger(AttributeA == 0 && Triggered == false);
Triggered = true;

"Triggered" will be initialized by default to 0 (false). Then at the second frame Triggered will be true, so "Triggered == false" will not pass.

answered by Jordan (14.6k points)
It's not working. It's treating it like it's on false all the time, as if the Triggered doesn't turn to true in the second frame or reverts back. The particles are still triggering every frame.
This solution will work only for each particles: each particle will trigger only once the event. So if you have say 10 particle/sec, il will trigger 10 event/sec.
I'll answer another solution.
...