Move a Visual Effect's position in World Space during Runtime?

I am using URP and VFXGraph 10.5.1 and the docs for this don’t really seem to cover this. I’ve tried doing conventional stuff like updating it’s position in Update() and I’ve tried using the PropertyBinder to no avail. I’ve looked extensively through the docs and I can’t seem to figure it out either due to ignorance or incompetence.

I have a visual effect that does a rain effect. I set it’s bounds, center, lifetime, all that stuff, that works fine. It’s sized so that the rain will last slightly longer than the height of the camera’s view.

The part I cannot appear to figure out on my own is setting it’s position and updating it to follow the player so it stays on the camera in the same spot while the player moves in the game world. This is 2d so not z axis involved, I don’t need to worry about walking around the world with rain, it just needs to be falling in the bounds that I have set

To achieve this I want to have it follow the player’s position. How can I achieve this?

Thank you in advance for any insight into this.

There is nothing extraordinary in moving vfx object, however this is a bit chaotic description, I am not sure what is the question :smile:

This is my guess: bounds of your system are in local space while your particles run in world space. In result whole rain just disappears when you don’t look at object origin. In any case please check your bounds and simulation settings. If this does not help please refine your question a bit and show your graph or something.

1 Like

Sorry, I know it’s all over the place. I’ve updated the question to simplify it.

As of right now I have the bounds and center and all that set on awake and then the visual effect just in that position. Neither MonoBehavior.Update() nor PropertyBinder.UpdateBinding() appear to have any effect.

Also, which system are you referring too, in regards to local vs world space? Maybe I am lacking some key knowledge that I need an understanding of for this to be more intuitive?

And simulation settings, are you talking about physics?

I am talking about this small “L” or “W” and simulation space of whole system (local/world) - bottom of this page.
If your vfx instantly vanish (being culled), it means bounds are not visible. When you set bounds position to local space (0,0,0) it means they move with the object, so when you move it, bounds do as well. If you set world (0,0,0) it means it will always stay in world origin and it does not matter where your rain drops spawn etc. it will be culled by camera if you don’t look there.

If I had 3D game in first person and wanted to spawn rain with vfx I would set simulation to world, so particles don’t move with parent object and spawn rain drops around character. If you want your rain literally to move with your character (this is what I understood), then you need both bounds and simulation space in local space and update vfx transform to be the same as character, camera or whatever is your point of reference.

1 Like

So I believe it’s all world space, the game is 2d. So I don’t have any z axis / depth.

Okay so I’ll try this out and make everything in the vfx local.

So I tried making it entirely local, and assign it’s gameObject’s position to the player as well as calling it from the vfx component .transform. No success. Same outcome as with global, the rain sits in the middle of the scene. The position of either is not updated. It seems to completely ignore it. Although the debug.log from the update if statement logs so it’s definitely running and looping through the code that should do make it move to the player’s position.

Here are the 3 methods called in this class. Follow() is called in awake but I have so many comments in there I can’t capture on single screen. Grabs objects and components and then update runs logging that isNull is false so it should work continuously.

Edit: Apparently I cannot retrieve this visual effect, I’ve been doing this for a while now and this works with everything but the gameobject that has the visual effect on it. It behaves like an inactive object even though it’s active. I don’t get it. So it’s null basically. The only way I can get the variable is to create a new one with gameObject.AddComponent<VisualEffect(); and assign it the rain visualeffectasset. But it doesn’t show up anywhere.

Edit2: Oh my lord it works… For whatever reason, I had to just create it with addcomponent, but I forgot to uncomment the line to add the visualeffectasset into it. Works exactly as intended after switching to local world space, thank you so much!


So to be clear, did you switch everything back to WORLD space?
or did you change everything to LOCAL space?

You probably try to find solution to question in the other thread, so if you set both to local (0,0,0) it should be exactly in the same place as parent transform. However this should always work, does not matter what device you test, so you most likely encountered a bug or it’s just not supported on that device, maybe it’s AR thing.

I switched everything to local. That way the positioning is set within the local space of the gameobject. Where as when it was world space, it was setting the position of the particle explicitly in the world space, so no matter where I moved the position of the gameobject, the positions of the visualeffect’s particles were being maintained in the exact trajectory based on world space that the visual effect was setting irrespective of the world position of the gameobject. Local means that it’s respective to the gameobject’s position so moving the gameobject changes the where the anchor so to speak is so naturally, that means all the particles move with it. I was so dumb I had assumed it was local space by default as moving a parent of a monobehavior component causes them to move with the parent respective to the parent’s local space, visual effect system however determines world or local in the graph, parent object has no control of that. Hope that helps.

1 Like