Search Unity

Question Instantiated VIsualEffect does not play

Discussion in 'Visual Effect Graph' started by WavyRancheros, Mar 3, 2022.

  1. WavyRancheros

    WavyRancheros

    Joined:
    Feb 5, 2013
    Posts:
    176
    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?
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    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?
     
  3. melong

    melong

    Joined:
    Sep 2, 2011
    Posts:
    22
    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.
     
  4. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    154
    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.
     
    Last edited: Mar 21, 2022
  5. taida-zero

    taida-zero

    Joined:
    Jun 5, 2022
    Posts:
    19
    I have the same problem I just created new "gameObject" and give it the
    "VisualEffect" component of the prefab
    upload_2024-2-24_11-9-43.png