hi everyone im billy.
i need help triggering one-shot particle effects in unity while using dialogue. i have the particle systems i want but i need help triggering them during dialogue. from what i understand particles can be triggered using colliders, but if im talking to an NPC i dont want to be moving around so what do i do?? ive been going over the manual for days and trying to do it myself but im very new to scripting so it hasnt stuck with me at all. please help thank you
need help triggering particles while in dialogue
Re: need help triggering particles while in dialogue
Hi Billy,
Here's a way to do it without colliders or scripts:
1. Create a particle system with these parameters:
2. Make MyParticleEffect a child of an active GameObject. For example, create an empty GameObject named "ParticleSystems" positioned at (0,0,0). Then make MyParticleEffect a child of ParticleSystems. Deactivate MyParticleEffect, but leave ParticleSystems active.
3. To one-shot the particle effect during dialogue, add this to the dialogue entry node's Sequence field:
This will be a true one-shot effect, as in it will only run once in the scene. If you need it to be able to re-run every time the conversation hits this dialogue entry node (for example, if the player revisits the conversation), let me know; I'll describe how to do that.
Here's a way to do it without colliders or scripts:
1. Create a particle system with these parameters:
- Duration: The duration you want the particle effect to last.
- Looping: Unticked.
- Play On Awake: Ticked.
2. Make MyParticleEffect a child of an active GameObject. For example, create an empty GameObject named "ParticleSystems" positioned at (0,0,0). Then make MyParticleEffect a child of ParticleSystems. Deactivate MyParticleEffect, but leave ParticleSystems active.
3. To one-shot the particle effect during dialogue, add this to the dialogue entry node's Sequence field:
Code: Select all
SetActive(MyParticleEffect)
Re: need help triggering particles while in dialogue
thank you so so much that worked perfectly. and for my purposes i won't be re-running the same conversation, but im interested in knowing how to trigger a particle if i wanted it to loop? like the same thing you did with the one-shot, but having it loop until the next section of dialogue?
Re: need help triggering particles while in dialogue
The heavy-handed way is to use the SetActive() command again to deactivate the GameObject:
However, the more graceful way is to write a custom sequencer command. You can create a C# script file named SequencerCommandParticleSystem containing this code:
This will add a sequencer command ParticleSystem() that takes two parameters. The first is the GameObject name, same as the SetActive() command you used. The second is "play", "pause", or "stop" (without quotes). For example, this sequence will start the particle effect at the 1-second mark and then stop it gracefully (allowing the current particles to fade out naturally) at the 3-second mark:
I added the "required" keyword to guarantee that the Dialogue System runs the stop command even if the player cancels the dialogue entry early.
Code: Select all
SetActive(MyParticleEffect,false)
Code: Select all
using UnityEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands {
public class SequencerCommandParticleSystem : SequencerCommand {
public void Start() {
var subject = GetSubject(0);
var command = GetParameter(1);
var particleSystem = (subject != null) ? subject.GetComponent<ParticleSystem>() : null;
if (particleSystem == null) {
if (DialogueDebug.LogWarnings) Debug.LogWarning("Dialogue System: Sequencer: ParticleSystem(" + GetParameters() + "): Can't find a ParticleSystem on " + GetParameter(0));
} else {
if (DialogueDebug.LogInfo) Debug.Log("Dialogue System: Sequencer: ParticleSystem(" + particleSystem + ", " + command + ")", particleSystem);
if (string.Equals(command, "play", System.StringComparison.OrdinalIgnoreCase)) {
particleSystem.Play();
} else if (string.Equals(command, "pause", System.StringComparison.OrdinalIgnoreCase)) {
particleSystem.Pause();
} else if (string.Equals(command, "stop", System.StringComparison.OrdinalIgnoreCase)) {
particleSystem.Stop();
} else {
if (DialogueDebug.LogWarnings) Debug.LogWarning("Dialogue System: Sequencer: ParticleSystem(" + GetParameters() + "): Unrecognized command " + GetParameter(1));
}
Stop();
}
}
}
}
Code: Select all
ParticleSystem(MyParticleEffect,play)@1;
required ParticleSystem(MyParticleEffect,stop)@3