Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice

VFX - setting Tex Index does not work

Discussion in 'Graphics Experimental Previews' started by sergiusz308, Nov 4, 2019.

  1. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    Hello there, I have this simple graph with 1x2 atlas and trying to set a atlas index in Initialization context but it always renders first frame only.

    Setting Tex Index to zero shows red color (first frame):

    upload_2019-11-4_13-36-52.png

    Setting Tex Index to 1 (or whatever other number) also shows only first frame (red) instead of second one (green):

    upload_2019-11-4_13-37-48.png
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi @sergiusz308,
    Did you try in update? I think it should work OK. Don't use initialize context which I presume is above your empty update.

    textureindex.png

    Just a thought - If you are going to do flip book plane with alpha in front of a gun, maybe VFX Graph is not the ideal tool for this as it can do so much more :)
     
    Last edited: Nov 4, 2019
    sergiusz308 likes this.
  3. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    @Olmi you mean add "set tex index" in the update? I want it to be randomized - as @JulienF_Unity suggested in other post to put it in the init context - I did it and it seems not being taken into account whatsoever.

    If I'd have a single value maybe putting it in the update would do the trick but I want it to be initialized to random value and then play using that value. There's even a block called "Set Tex Index Random" and it does not work either :(

    About using VFX being for much more - I am looking at it from code/assets mgmt point of view: it's easier to deal with a single particle system than multiple ones. Here it's a simple muzzle flash for a gun, but for other weapons we can have much more elaborated effects.
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Well can't you set the random value from outside, C#? You could use some exposed parameter and set a random value there. Or just set random int value inside VFX Graph.

    I'm not sure if I understand correctly. You want to set a single frame or a start frame. What do you mean with play? Play the flipbook sequence from that point forward? You would need to limit the range somehow if you want to play a region of your flipbook, like from frame 4-10, for example, so that it would wrap around.
     
  5. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    I got two frames playbook and at each burst I just want to show a single frame, selected randomly. So in the example above it's a simple red and green rectangle - at each burst I want it to be red or green, picked randomly and displayed throughout the particle life.
     
  6. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Well, I think you can then just set the index through exposed parameter, if random doesn't function inside VFX Graph for some reason.
     
    sergiusz308 likes this.
  7. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    @Olmi - I will try that, but it looks like a bug.
     
  8. Loumiskme

    Loumiskme

    Joined:
    Feb 17, 2019
    Posts:
    2
  9. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @sergiusz308 , I just tried it and cannot reproduce your issue.
    In your example, did you per chance spawn the particle once and after that tried to change the value in Initialize?

    If so, Initialize, much like Start() in C#, gets called once at the birth of the particle, so after the particle is born, changing any value in Initialize will not update anything.

    If you recompile the graph or spawn new particles, you should see the updated change.
    If you'd like to assign a new tex index after the particle has already been born, you can do so as @Olmi suggested in Update or even in Output.

    And if you wanted to set a random value that does not change, you can use a Random Number with the constant checkbox selected. Here's an example for both:

    Hope this helps!
    Please let me know if I am misunderstanding the issue.
     

    Attached Files:

  10. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    235
    @VladVNeykov Thanks for looking into this.

    Anyway, I end up with this setup:

    upload_2019-11-14_18-52-57.png

    Upon clicking "play" it gives random value for the tex index.
     

    Attached Files:

    VladVNeykov likes this.