Search Unity

Syncing VFXgraph playback with Alembic animation

Discussion in 'Visual Effect Graph' started by Mindtoast451, Sep 13, 2021.

  1. Mindtoast451

    Mindtoast451

    Joined:
    Aug 2, 2013
    Posts:
    6
    I'm working on a project where I am using an Alembic cached animation and VFX graph effects with a timeline to sequence the animation. Is there a way to update vfx graph particles to be controlled by the game time/timeline time control instead of just being activated by OnPlay events. Or, to put it another way, to control the exact frame the vfx graph is at relative to a start time, like an animation clip? I understand that's not really how VFXgraph works with the timeline, but is there a way to control the vfx graph update loop? I have only been using VFXgraph for so long, and I'm not aware of a way to control the update loops synchronization with game time.
     
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    443
    Hi @Mindtoast451,
    I'm not sure how your effect is structured, so the following might or might not work.
    In some cases you can make your own "custom time" (really, just an exposed float which you can then animate in timeline) and use it to drive the changes in your graph: modify values, lerp between colors, etc. This approach works fairly well for changed you are making in the Output (modifying positions, sizes, setting particles as alive/not alive, etc.), but will not work well for changes in Update (modifying positions, working with collisions, triggers/GPU events, etc.).

    Since Outputs receive their particle attribute values from Update each frame, you are only modifying them for that frame, which means you can do things in Outputs like toggle them off (set alive to false) and later turn them back on (set alive to true) without actually killing the particles like you would if you do the same in Update.

    In this example, I have particles spawned in a shape in Initialize and am adding noise to the position in Output, which is connected to an exposed float (which can be animated in timeline outside of your graph):


    Alternatively, you can do something similar, but with the Update loop by exposing a float which will be your custom deltaTime. For this to work, you need to first disable the automatic updating of position and/or rotation in your Update:


    Particle positions in Update change based on:
    position += velocity * deltaTime;

    And their rotations change based on:

    angleX += angularVelocityX * deltaTime;
    angleY += angularVelocityY * deltaTime;
    angleZ += angularVelocityZ * deltaTime;

    So you can do this manually like this:


    Then all you have to do is feed your own deltaTime to the exposed float to update at your own desired rate (i.e. from timeline).

    Hope some of this might help :)
     

    Attached Files:

  3. vladala

    vladala

    Unity Technologies

    Joined:
    Mar 3, 2017
    Posts:
    109
    It's gonna be cumbersome, but a timeline integration would be in the lines of:
    1)Make a VFXGraph with a custom double for time.
    2) Make a custom timeline track that binds to the VisualEffect that takes the timeline time and pushes in the custom time parameter.
     
  4. Mindtoast451

    Mindtoast451

    Joined:
    Aug 2, 2013
    Posts:
    6
    Thanks, I'm going to give that a try. That sounds like it will do what I want it to do. The effect I'm working on is a planetary collision. I have the planet geometry cached as an alembic animation and I'm trying to get an impact shockwave VFX effect to sync with the impact of the planetoid bodies. The VFX were lagging behind while the alembic animation keeps playing at a fixed frame rate.
     
unityunity