- Home /
How to Play ParticleSystem from AnimationEvent?
Hi
I'm trying to play a Particle System from an Animation Event.
I created the event on the animation clip and assigned the name of the function that I want to run to ShowMuzzle. For reasons unknown to me the Event its called but the particle never shows.
I even create an Editor Extension to invoke the method on PlayMode. When I use my custom button it gets called and the particle shows up, but when I use the animation event the particle is never shown.
Here is the Code of the ShowMuzzle Method:
public class WeaponAnimator : MonoBehaviour, IWeaponAnimator
{
[SerializeField]
private GameObject particleEmitorContainer;
[SerializeField]
private GameObject dropableModel;
[SerializeField]
private GameObject projectileSpawner;
public GameObject ParticleEmitorContainer => particleEmitorContainer;
public GameObject ProjectileSpawner => projectileSpawner;
public GameObject DropableModel => dropableModel;
public void ShowMuzzle()
{
foreach (var particle in particleEmitorContainer?.transform.GetComponentsInChildren<ParticleSystem>())
{
particle.Play();
}
Debug.Log("MuzzlePlayed");
}
}
And here is my code for the Editor Extension to Call the metod:
[CustomEditor(typeof(WeaponAnimator))]
public class WeaponAnimatorEventRaiser : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
GUI.enabled = Application.isPlaying;
var animator = target as WeaponAnimator;
if (GUILayout.Button("Invoke Particle"))
{
animator.ShowMuzzle();
}
}
}
Any Idea on why the particle is not shown using the AnimationEvent?
Your answer
Follow this Question
Related Questions
Change particle size based on how near it is to a given point or height 2 Answers
Is their any way to save a particle system when it's not instantiated yet? 2 Answers
How can i use AnimationEvent and SendMessageOptions.DontRequireReceiver ? 1 Answer
How to instanciate a particle system prefab to a certain moving game objects position? 2 Answers
Using a Burst in a script 3 Answers