Search Unity

Help Wanted Trigger C# Script

Discussion in 'Visual Effect Graph' started by pbritton, Jun 8, 2021.

  1. pbritton

    pbritton

    Joined:
    Nov 14, 2016
    Posts:
    94
    How would I trigger a C# function from Visual Effect Graph? I can't seem to find a clear or any answer on this. I see there is some posts about events but none of them directly or indirectly lead me down the right path.
     
  2. JLM_fell

    JLM_fell

    Joined:
    Jul 26, 2018
    Posts:
    6
    • I am also looking for a solution to this problem
     
  3. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    442
    Hi, this forum thread has more information on the topic, but in a nutshell, the VFX Graph particles are simulated on the GPU, so you won't be able for example to send an event to C# when a particle hits something.

    We plan on adding the ability to read the particle attribute buffers from the CPU, but sending data from the GPU to the CPU will always have some performance impact. CPU simulation for the VFX Graph is also planned down the road, but the focus is first on the GPU side.

    We have support since VFX 10.x for CPU events which are connected to the Spawner context, so you can send an event to your C# when particles are first spawned, but you won't be able to trigger it later in the graph.

    There's also GPU events, in which one system can send events to another system (i.e. to spawn particles in the location where particles die, like in a fireworks-type effect).

    Sometimes it's worthwhile to keep your logic on the CPU side, for example if you are having rockets which need to impact with something, then Raycasting in C# and sending over an event to the VFX graph to create an explosion is a better workflow than controlling the rockets from within the VFX Graph and not being able to affect your scene on the CPU side.

    Can you describe your exact scenario(s) you are trying to accomplish?
     
  4. JLM_fell

    JLM_fell

    Joined:
    Jul 26, 2018
    Posts:
    6
    I am studying the game of barrette shooting, we can make various shapes of barrette through Vfx, and then I hope to make these barrette can collide with the character and produce a logic of character damage reduction
     
  5. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    442
    Sorry, I'm not familiar with barrette's; wikipedia suggests it's a form of hair clip?

    Any time you want VFX particles to collide and produce a reaction within your scene, you should think the other way around; have some empty game objects with collision components (spheres, boxes, or some custom mesh) representing your barrettes, and do your collision/damage logic as you would normally do if you weren't using the VFX Graph. Then, for the visuals, use the position of these placeholder objects to update the visuals created by the VFX Graph to follow them. You can send large amounts of data using Graphics Buffers in 2021.2 onwards.
     
  6. JLM_fell

    JLM_fell

    Joined:
    Jul 26, 2018
    Posts:
    6
    • Sorry,It's a STG type of shooter
     
unityunity