Search Unity

Question Access world scale of Visual Effect's game object?

Discussion in 'Visual Effect Graph' started by dgoyette, Jul 3, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I can access the world position of the system using the Transform (Position) node. But I don't see a way to access the current scale of the object. For example, if I either set the scale of the system to 5 along the x-axis, or I do that to a parent object of the system, how can I access that value of 5? I don't see any nodes providing scale.

    I want to do this so that the spawn rate can be relative to the scaling.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    So far, I've found one way to do this, but it feels kind of hacky. You can expose a Transform property in the graph, and then bind that to an object using a Property Binder component:

    upload_2020-7-3_17-21-0.png

    upload_2020-7-3_17-21-20.png

    However, I wasn't able to get this to work off the world scale of an object whose parent had been scaled. So I had to set it to the local scale of the parent that I was scaling.

    I'm assuming there's a better way to get the world scale of the child object, and that this Property Binder approach isn't really the correct way to access the world transform info of the object the Visual Effect is on?
     
  3. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    Any better technique for this? I'm surprised I can't easily emit a particle in world space scaled by the parent transform.
     
  4. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    Ended up using property binder and this worked cleanly!
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Were you ever able to find solution to this problem ?

    I want to have my particles scale independent, but want to keep my particle system as local.
    And I don't want to care about scale somewhere in hierarchy of parents of my VFX.
     
  6. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    Parent scale might be different for axes for example (0.3, 0.6, 0.3), for this reason I am not sure if this is trivial problem.
    You could maybe try to extract scale difference using world to local or actually local to world, then pick the largest or smallest component and multiply by size of particles to spawn them adjusted.

    Actually I think there was also some operator node that returns object scale, but I might be wrong.
     
    koirat likes this.
  7. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    In the end decided to go with world space for particle.
    It was still problematic but managed to tame it in the end.
    But thank you for your effort anyway.
     
  8. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    No other solution than what I mentioned. I'm not sure if there is a better approach by this point, but I'm still using a property binder to pass the scale to the Visual Effect.
     
    koirat likes this.
  9. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    In this case I am going to answer the original question.

    Local To World node returns transform of visual effect. The result should be the same as using property binder above.
    upload_2023-3-30_13-15-17.png
    The system in the picture is in world space, so the result should be particles scaled in the same way as particles in local space (but without any additional setup). Furthermore you can do inverse for system in local space using World To Local, however I am unable to tell if result will be always "good" if scale is non uniform.
     
  10. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Already tried this and all possible combinations, without the success.
    I might give it a try tomorrow, but don't have high hopes.

    To be more precise it does work on uniform scale, but non uniform gives me problems.
    Also you have to set WorldToLocal and not LocalToWorld in local space. Since you need inversion.

    [Edit]
    I could not go to sleep with this problem unsolved - and I think I have made it.
    But need to test more. I will be back.
    [/edit]
     
    Last edited: Mar 31, 2023
  11. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    And...
    I was not able to make it in the end. (some cases with rotation).
    I cannot invest any more time into it, especially that such a behavior should be built in. (checkbox on Output "Ignore Transform Scale" or similar)

    Question stands open how to parent vfx (in local space) into arbitrary point in hierarchy of game objects and prevent scaling of single particles.