Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug VFX Graph behaving oddly when setting renderer.material

Discussion in 'Visual Effect Graph' started by jtheis85, Sep 10, 2023.

  1. jtheis85

    jtheis85

    Joined:
    Oct 13, 2021
    Posts:
    19
    I have a vehicle prefab that I spawn based on player input (in this case, just clicking on the ground spawns the vehicle). The prefab has a child object with a VFX graph object attached to it.

    At first I though the VFX weren't playing. But then I noticed a TINY, unmoving particle.

    upload_2023-9-9_20-25-44.png

    When I touch ANY graph property in the inspector (even one that's not hooked up to anything!) it magically starts to work correctly:

    upload_2023-9-9_20-27-48.png

    IMPORTANT: This does NOT seem to be an issue with Play/Stop or anything related, as I thought it was at first. If the effect isn't playing, the incorrect tiny/unmoving particles (circled in Green above) disappear entirely. And when the effect IS playing, they appear (again, incorrectly). Only a "touch" of the inspector seems to get it working as expected. It's as through the spawn and particle render are working, but all of the size/position/rotation being done in the graph is being ignored. Note that if I drag the VFX directly into the scene, it works without issue.

    I am using Unity 2022.3.5f1 and Visual Effect Graph 14.0.8, URP 14.0.8. This setup was working as expected on an earlier version of Unity (but I don't remember which exact version it was, as I only recently noticed this VFX missing after doing at least one if not 2 unity version updates).

    The graph itself is pretty basic, and you can ignore most of the params in this case, as they mostly serve to adjust the color and slightly offset the spawn position.

    upload_2023-9-9_20-31-47.png
     
    Last edited: Sep 10, 2023
  2. jtheis85

    jtheis85

    Joined:
    Oct 13, 2021
    Posts:
    19
    Update: I discovered the cause.

    A script elsewhere on my vehicle (responsible for making it visible/invisible for gameplay purposes) was making this call:


    Code (CSharp):
    1. renderers = new List<Renderer>(GetComponentsInChildren<Renderer>());
    2. foreach (var renderer in renderers)
    3. {
    4.     renderer.material.SetFloat("_Opacity", 1f);
    5. }
    and adding a check for

    Code (CSharp):
    1. if(renderer.material.HasFloat("_Opacity"))
    fixed the issue.

    It seems odd that setting a property that doesn't exist on a material has the effect that I observed above. What's going on here?