I want to make a muzzleFlash for my weapon, and I wanna make that when I press the “shooting” button, it plays the visual effect graph, but I don’t know how to make a reference of it on visual studio, I wrote “public VisualEffectGraph muzzleFlash”, but it doesn’t recognize the VFX, so can someone help me to find a way to play de VFX by code?
Graph is just asset, it describes the vfx, but it has nothing to do with playing it.
VisualEffect is the component you use to play the effect. Also here is example how to send event with attributes in case you need it.
Ok, thanks!
I’ve noticed that the Event block defaults to OnPlay as its name, and that the instantiation of the VisualEffect component with this event initiates this event. I found that changing the name to anything other than OnPlay will not initiate the play upon instantiation, but will allow me to trigger it with the name I give it. For example, I change OnPlay to FireProjectile, and then in my code I use that to play the VFX.
VFXEventAttribute EventSettings = VFX.CreateVFXEventAttribute();
EventSettings.SetInt("ID", unitid);
EventSettings.SetVector3("VelocityN", Velocity * 10);
VFX.SendEvent("FireProjectile", EventSettings);
