Search Unity

Why does "Output Particle xx" context work like "Update Particle" ?

Discussion in 'Visual Effect Graph' started by Henry_Sun, Mar 17, 2022.

  1. Henry_Sun

    Henry_Sun

    Joined:
    Jun 1, 2019
    Posts:
    24
    I mean updating my particles in" Update Particle" context. It makes sense.
    But I can also use update particles attribute nodes in "Output Particle xx" context ?
    And if you create a default VFX graph. You can see that Set Size over Life and Set Color over Life in the Output context.
    I mean why not just let the output context only handle the output settings.
    It's confusing me and my co-workers.
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    It might be confusing at the beginning, but it has purpose, so let me explain:
    Update context and Output context does not work in the same way - if you update particle in update context you work on real particle data and it will be persisted, while update in output context is lost, it exists only for duration of rendering (current frame).
    Most of the time it doesn't matter, however if you make something more complex it's very handy, let me give you few examples:
    • Single system can have multiple outputs, for example 3. In this case you can update particle once in update and render it 3 times from the same data, otherwise you would need to calculate it 3 times what is worse for performance and not desired - you don't want to simulate physics 3 times.
    • Performance aside, you can set scale in update and then set (or multiply / add) it again in output based on that value, so for example particle rendered in second context is twice as big. You can do anything you want, like displace particle or change color.
    • Even if there is only one output you can do things you couldn't do without that system, for example kill particle. You can set particle
      alive = false
      in output, so it won't be rendered, but only for the current frame, because you work on copy of real particle data. If you did it in the update, then it would die forever.
    As you can see it does not matter for most of systems, but it's important to at least understand the difference between output and update context, so that you don't look for strange bugs in future.
     
    Henry_Sun and VladVNeykov like this.
  3. Mayumichi

    Mayumichi

    Joined:
    Mar 12, 2017
    Posts:
    31
    You can have multiple update and output contexts, the choice is yours where you put what. If you want you could just remove the update and go straight from init to output. For some complex graphs it's more performant and easier to manage if you do general stuff in a common update, then further modify it in the output context.
     
    Henry_Sun, VladVNeykov and Qriva like this.
  4. Henry_Sun

    Henry_Sun

    Joined:
    Jun 1, 2019
    Posts:
    24
    Thank all you guys ! I get it now.
     
  5. Vita-

    Vita-

    Unity Technologies

    Joined:
    Jul 2, 2019
    Posts:
    121
    Hi all!

    Great to see an active discussion, just one note that in the screenshot above we can see flow link violation.

    Mixing Update and Output from the same flow port should be prohibited. For example, we should not be able to connect Output and Update to the same Initialize. Invalid connection issue is fixed in 2022.1.0a16, 2021.2.14f1 and above. It is also going to be backported to 2020 LTS.

    Here's the Issue Tracker of the issue.
     
    VladVNeykov and Qriva like this.
  6. Mayumichi

    Mayumichi

    Joined:
    Mar 12, 2017
    Posts:
    31
    Just to clarify, the top right output node is the invalid one? Otherwise it'd be fine? Apologies for the mistake, just thew a "complicated" setup together to demonstrate and I had just downgraded to 2020 for Entities 0.50 :p
     
  7. Vita-

    Vita-

    Unity Technologies

    Joined:
    Jul 2, 2019
    Posts:
    121
    Not at all, this oopsie is on us. :)

    You can connect Output to the Initialize, it is a valid operation, but mixing Update and Output connection from the same flow port should not be allowed. Once you connect Output to the Initialize, Update Context should be disconnected. Same where the Update and Output both are connected to the Update context above (in your attached screenshot), this one showcase invalid behavior as well.

    Attaching a short gif illustrating what we expect to happen when we are trying to mix Update and Output connection to the same flow port. If this does not clarify things out, happy to answer any further question!
    Unity_jVGYSRgsAe.gif
     
    Mayumichi likes this.