Search Unity

Question Confused about how to prevent play-on-awake behavior

Discussion in 'Visual Effect Graph' started by dgoyette, May 22, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I have some Visual Effects that I want to just sit there doing nothing until I call Play() on them. However, it seems that they'll always immediately play when the scene starts.

    To avoid this, I removed the "Initial Event Name" from the graph, and instead I pass in an event argument to start the graph. That's fine in play mode, but now I can't play the Visual Effect in the editor using the Play Controls window.

    So what's the trick? The only other way I know to prevent the Visual Effect from playing immediately on entering play mode is for the Visual Effect to not be active. But then I once again can't play the effect in the editor using the gizmo.

    So, to recap: I'd like to prevent Visual Effects from playing upon entering Play Mode, and only play when I tell them to play via some code. But I want to be able to play the visual effect in the editor using the Play Controls window. What am I missing?
     
    Gametyme likes this.
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @dgoyette ,

    You can add a custom event and connect it to your Spawner. Then you can trigger it in both edit and play mode from within the VFX Graph to start your system:


    If you would like to control it from the scene view, you can use the Event Tester and pass your event from there:


    You can also access is in the Target GameObject menu (it attached the VFX to a specific instance in the scene). You can see that all events you add to your graph will be listed at the bottom and can be triggered from here too:


    Hope this helps!
     

    Attached Files:

  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    That's extremely helpful. Thanks.
     
    VladVNeykov likes this.
  4. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Is using an event this way preferred over simply enabling or disabling the VFX game object? @VladVNeykov
     
  5. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Depends what you are trying to do.

    Toggling a game object just re-triggers the initial event (by default "OnPlay")

    which acts the same as if you've had this setup:


    So in a way, you are always using an event, even if it is implicitly by default the OnPlay event.

    Using other events though allows you to decide when the effect starts/stops, like in the OP's inquiry on not having the effects start automatically, but only when a specific event is called, or to even trigger a system multiple times (for example, if you had a Single Burst block in the spawner and you wanted to trigger a few single bursts at specific times).

    Hope this helps!
     

    Attached Files:

    Last edited: May 5, 2021
  6. Livealot

    Livealot

    Joined:
    Sep 2, 2013
    Posts:
    228
    If your VFX setups use managers like mine do, I have a habit of calling Stop() in the Start function after initializing the VFX. Then I call Play() when needed.
     
    vfirstof likes this.
  7. FlightOfOne

    FlightOfOne

    Joined:
    Aug 1, 2014
    Posts:
    668
    Yeah this is what I ended up doing. I have a feeling this calls an event anyways. I was having a problem though. When I call play system would not immediately play, it would linger for a second or so. These were muzzle flashes so had to play instantly. I discovered that this was because I had just enabled the game object. Now I never disable particles, just stop and play like you said.
     
    ATate and Livealot like this.