Search Unity

Spawn over a broken line

Discussion in 'Visual Effect Graph' started by talofen, Feb 25, 2020.

  1. talofen

    talofen

    Joined:
    Jan 1, 2019
    Posts:
    40
    I have a Line component (an array of positions). I would like to spawn particles over the whole line, but I could not find a way to pass it to the VFX Graph.
    Any suggestions?
     
  2. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
    The only easy way I can think of is to make a point cache from the coordinates you have with some points in between and use it on the graph with the set position from map.
     
  3. talofen

    talofen

    Joined:
    Jan 1, 2019
    Posts:
    40
    I’ve never worked with point caches. I’ll try to find something. The documentation is quite scarce on the subject...
    I found there is a tool to baked it, but I’ll need to create it at runtime...
     
  4. VladVNeykov

    VladVNeykov

    Unity Technologies

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

    You can also save the line segment positions in a texture, assign it to an exposed Texture2D property, and read it within the VFX Graph. As an example, take a look of the Multiple Position Binder, which saves the positions of all referenced transforms in a texture.
     
    florianhanke likes this.
  5. talofen

    talofen

    Joined:
    Jan 1, 2019
    Posts:
    40
    Thank you. This seems an easier solution...I will check the provided assets and source code to see if it can fit my needs!
     
  6. talofen

    talofen

    Joined:
    Jan 1, 2019
    Posts:
    40
    I'm trying to implement your solution. I almost succeeded.
    - copied the VFX Graph part from you asset
    - Added the Multiple Position Binder component
    - I instantiate the gameobjects (one for every vertex ov my line)


    Now the problem. How do I access the Targets GameObjects[] from script? I can add them thru the editor, but I need to create the Targets array and populate it at runtime. I found no obvious way to access it... I'm sorry, I tried, but the documentation seems rather scarce....

    Any suggestion is very welcome. Thank you!
     
  7. talofen

    talofen

    Joined:
    Jan 1, 2019
    Posts:
    40
    I solved.
    I modified the Multiple Position Binder. First of all, I changed the GameObject[] to a List<Vector3> which is more maneageble.
    Then, I still don't know why but I could not access it from outside. So, I exploited a small trick: in the Biinder code, I exposed a
    public GameObject go;
    List<Vector3> targets;
    In the editor, I referenced it to the same gameObject that had the VFX Graph. Then, I made a script and attached it to my GameObject, called Track. The Track script exposed a public
    List<Vector3> positions;
    that will contain the positions I will deal with.

    in the Binder script, I made it Get this Component and referenced
    Track track = go.GetComponent<Track>();
    targets=track.positions;

    This did the trick. If someone is interested, I can pack a small prefab and upload it somewhere.

    Thank you all.
     
    VladVNeykov likes this.
  8. marcuslelus

    marcuslelus

    Joined:
    Jun 18, 2018
    Posts:
    67
    I am very interested by that prefab, if it's not too much to ask :)
     
  9. talofen

    talofen

    Joined:
    Jan 1, 2019
    Posts:
    40
  10. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    589
    @VladVNeykov Is there a way to assign the Multiple Position Targets in code? I am using a mesh to generate the points at runtime, instantiating a gameobject at position in the center of each triangle. I'd like to assign that list of gameobjects as the target of the Multiple Position binder.

    For anyone trying to do the same thing, here is my setup with static gameobjects that works well:

    Screen Shot 2021-03-26 at 5.49.19 PM.png Screen Shot 2021-03-26 at 5.50.21 PM.png