- Home /
Turn on Shuriken "Simulate" from script in Edit mode?
Hi all,
In one of my workflow scripts, I have a hotkey so I can play only a selected particle system within a prefab (as opposed to playing the whole thing, or having to manually disable the pieces I don't want to see.)
The "problem" is, this only works in Edit mode if the Simulate button has been pressed. Alternatively, it works in Play mode without any additional steps.
I would REALLY like to be able to trigger Simulate from my script, to save me the button press (I work with a LOT of effects, this would be a time saver for me).
Is it possible? I'm going to guess not, but thought I'd ask.
I haven't tried it, but you might be able to call Simulate directly? You'd probably need it to be called once per frame by a script that has ExecuteInEdit$$anonymous$$ode.
I could have sworn I've seen methods to "fake" clicks on the Unity Editor UI, but I'm not turning any of them up in my searches right now. Will post back if I find them.
Answer by dbarth · Feb 09, 2014 at 01:33 AM
I found the answer... I needed to add a validate method for my MenuItem method that was playing the selected particle... weird. Basically I have a method which returns whether the selected transform's gameObject has a ParticleSystem component. If it does, then my "play selected particle" method works, and turns on the "Simulate" you see in-editor.
This is NOT the same "Simulate" as the one found in the API for ParticleSystem... that one is used to simulate a specific time/state in the particle's duration, it does not turn on or interact with the editor's "Simulate" button. Kind of confusing.
Code looks a bit like this:
[MenuItem("...Play Selected Particle...")]
public static void PlaySelectedParticle() { ... }
// Validate above MenuItem
[MenuItem("...Play Selected Particle...", true)]
private static bool PlaySelectedParticleValidate() {
Does selected transform's GO have a ParticleSystem component?
}