Instantiated VIsualEffect does not play

Hey everyone,

I created a VFXGraph. I then turned the GameObject with the VisualEffect component into a prefab.

When I drag that Prefab into the scene in the Editor, the effect plays automatically. When I set the GameObject inactive and active, the effect plays.

But when I instantiate the prefab from script, nothing happens.

I tried vfx.Play(). I tried vfx.SendEvent(“OnPlay”). Nothing.

What am I doing wrong?

Maybe it plays actually, but you can’t see that because bounds of the effect are offscreen or position of the effect itself is wrong or world space or something similar?

I had a similar problem and could not find any reason why this was happening.

After some tests, i realized the Visual Effect component is of Type Renderer, and i had some code doing a GetComponentInChildren to get all renderers and then a material.SetFloat(“_SomeProperty”, someValue).

Even though the VFX graph doesn’t contain such property it made the VFX invisible and nothing i did in code could fix it (but touching anything in the inspector made it appear again).

So in the end Dodging the Visual Effect Renderer fixed the problem.

Hello,
About the unexpected behavior after calling renderer.material, what you are describing is probably relative to this issue.
Behind the curtain, the problem is about this documented behavior:
If the material is used by any other renderers, this will clone the shared material and start using it from now on.

In case of VFX, it will lead to a desynchronization between the material used by the VFXSystem and the one used by the rendering.

However, I’m not sure it’s related to the prefab issue previously mentioned.

I have the same problem I just created new “gameObject” and give it the
“VisualEffect” component of the prefab