Download

Offset UV by position - not working?

Hi!
I want to add an offset to a texture’s UV based on the objects position. I use it on trees so that the stems don’t all look the same.
I’ve set it up according to the material setup in this article under “offset detail UVs by rock’s X and Y position”. I’ve tried using several different position nodes, not only the ObjectPivotPoint but they all have the same problem.
When I take the asset from the Content Browser and place it in the level, the texture moves as expected, but as soon as I let go of the asset the texture goes back to “default” so that they all look the same regardless of their position. And then If I select the asset and move it around the texture is static as well. So why does the material not take the object position into consideration when it has been placed?

This is how my setup looks:

Try using a world position material for the trunk.

so, when you place or move an object it is usually on a grid i.e a round value (10, 25, 1005, etc) depending on your grid settings of course.
your uv mapping is in the space of 0 to 1 and using tileable textures probably so when you add a full number like 10 to your uv it will show the exact same thing because it shifts the whole uv space by x times.
you need to either divide that number to get into fractions or come up with a different system.
also, i use object position instead of pivot point because the pivot can be away from the model in some cases, object position uses the center of the bounding box if i’m not mistaking.


Use this as a material function, plug into UVs of texture sample directly, put how large of a texture it should be in uv size. It should just work.

When using instanced meshes like foliage, the object position is the center point of all foliage because they are all one object. So as you plop down another mesh, it slightly shifts the average position but all trees will look exactly the same as each other. You need to use a either a Per-Instance Random node, or the Vertex Interpolator node to accomplish the desired effect.

Thank you all for your advice, I think I’ve found a way to make it work now!
I wanted it to work on both foliage instanced meshes and also on hand placed static meshes so this is the setup I’ve used now to make the offset random for both.
I also couldn’t use the AbsoluteWorldPosition as my trees sway in the wind and then the textures don’t sway with the asset so that looks pretty odd.
Didn’t know about the PerInstanceRandom node so that one will be very useful for other things as well, thank you!
(The adds after the ObjectPivotPoint ComponentMasks are just there to add offset on all axis when moving an object on one single axis)

Just noticed that this setup ha caused an issue with the resolution of the texture on handplaced StaticMeshes. Foliage instances don’t seem to be affected by this.
The resolution of the texture is correct at the Origo 000 position in the world, but the further away the object is the lower the resolution gets. The first picture is a tree that is a couple of thousand units from 000, and the second is one close to 000.
The tiling is still correct, so I’m not sure why the resolution changes. Does anybody know?

The issue seems to be with the PerInstanceRandom, as it works when I unhook that one. Is there a workaround to this or will I have to set up two different materials, one for foliage instances and one for regular StaticMeshes?

Not sure why or how the per instance random could cause that, but if you can’t solve it just set up a bool parameter switch, and then create a separate material instance of the same material, or use the vertex Interpolator instead.