I think I’m just making myself go crazy here. And I’m quite sure there are a lot of simple solutions to this, but I might have confused myself.
public virtual void AnimationVFX()
{
var attackVfx = Instantiate(maData.vfx[attackCounter], transform.GetChild(0).position, this.transform.rotation) as GameObject;
attackVfx.transform.parent = gameObject.transform.GetChild(0).gameObject.transform;
Destroy(attackVfx, 1.5f);
}
I’m currently calling this as an animation event. It works perfectly.
On this prefab that I’m instantiating, I’ve got a visual effect graph.
I need to send it an event to stop.
I’m using the reference documents for this, and it’s also working. Almost.
public virtual void AnimationVFXOnStop(int whichVfxToStop)
{
VisualEffect[] boom = GetComponentsInChildren<VisualEffect>();
boom[whichVfxToStop].SendEvent("OnStop");
}
This was my atempt at making this work. It’s also called in an animation event. And it kind of works, but not really.
The whichVfxToStop int is there to help me be able to turn off specific visual effects on a single prefab, if I run multiple on the same one.
BUT, the issue now is that if I instantiate multiple prefabs, it can’t differentiate between them when calling the OnStop.
For example, if I give the input to instantiate twice quickly, it only sends the onstop event to first prefab twice, since the first prefab hasn’t been destroyed yet. So I need to be able to differentiate between specific instances.
How could I go about this?