Control Texture Offset with Character Velocity not working

Hello,

I created a material named ‘‘TV_Material’’. In that material, I want to make a texture offset on the U axis with a scalar parameter. I think I got that part right, because when I create a Material Instance and change the value of the scalar parameter, I see the texture offset properly in the material viewer, as well as on the mesh I apply it to in my level.

The tricky part is, I want to make it so every frame, when the character advances on the x axis (this is a 2D game), the texture of the mesh moves (offsets on the U axis) by one. So in my level, I created the following logic:

  1. On BeginPlay, I create a Dynamic Material instance of my material and set it as the material of the mesh in my level.
  2. Then, Every Tick, I check the character’s velocity. If lower than 0, then nothing. If greater than 0, then I get the scalar parameter’s value, I add 1 to it, and I make the result the new value of the parameter.

The logic works well when I print string it, and I can see the scalar parameter goes up when I move the character and stops when the character stops. The problem is, the texture isn’t moving. I tried multiple ways to troubleshoot it, and I can’t find the error in my logic. Like I said, the Scalar parameter works in the material viewer and in the scene. And the value gets updated properly when I print string it. But it’s not working.

What am I doing wrong? Here are screenshots of my setup.



How are you magically making that mesh variable? Are you getting ‘none’ errors after play?

No, I’m not getting error messages.

I click on my mesh in the level, and then I go in my level graph, I right click and select “Create Reference to Mesh”.

Should I not do that and instead put the mesh in an actor and use ‘‘Get all actor of Class’’? Or is there a better solution?

1 Like

This is the problem

The create dynamic mode already assigns the material to the mesh. With the ‘set material’ node, you’re assigning another material. Just remove that node… :slight_smile:

You are right. I changed it and now it does something.

However weirdly enough, it doesn’t do the right thing. Again, in the material editor, the material instance and in my level editor viewport, when I change the scalar parameter value, the texture offsets on the U axis (x) correctly. But in-game, the texture is instead stretching when I move my character forward, not offsetting.

Yet, the print string is showing the scalar parameter is going up by 1 each tick when the character moves forward, as intended. So I have no idea what I’m doing wrong.

I then replaced the ‘‘Get Scalar Parameter Value’’ with a custom Float setup. At Begin play, the value is reset to 0, and then I add 1 to it every tick, and make that the new value of the scalar parameter by plugging it into the Value input. It creates the same stretching problem.

I feel like the problem is the Set Scalar parameter value for some reason, but I don’t know of any other node setup that could replace it to test if that’s the case.



You need to set it to a single number once (which represent speed), not add to it.

Set it to 0 again when not moving.

There is no Panner node in the material though. So if every tick, I set the scalar parameter to a single number (let’s say 100), then it will move the texture on the X axis by 100 on the first tick, and every other tick, it will do nothing, because it’s constantly setting it to that value. Think of it as a ‘‘Set World Location’’ node basically.

Also, by resetting to 0 when the character stops, the texture will reset back it to it’s original position in 1 frame instead of staying in the offset where it was at.

Did you rename the parameter to X Offset?

Yah I did. I kept the same node and double checked that the parameter name was OK.

Maybe something to do with the vase mesh UV.

You’re reading my mind. This is exactly what I was checking in Blender. But everything looks fine. This screenshot shows the seam at the back of the vase. Only the front matters though, so I don’t care if the texture repeats itself on the 2 parts of the mesh that are outside of the texture, since it’s hidden behind.

Also, I just tried with a simple square plane. Same problem.

You could try the material on a unreal sphere mesh. See if it works there.

Same issue on a basic Unreal Sphere.

So at least I know the problem isn’t the material, or the mesh. It’s the Set Scalar Parameter Logic.

Does it move initially as it should? Try slower number.

It’s so weird. When I change the number in the Material instance, it offsets as intended, but if I go to an extremely high number, like over millions, the texture starts stretching just like in-game.

So I tried using smaller numbers but the texture doesn’t move at all. And If I try numbers in the middle, the texture doesn’t move, and then when the number starts getting high enough, it stretches. It just never offsets like in the instance.

Try 0.0001 or 0.001 and 0.01

I think uv-s range from 0 to 1.

Yup, that was it. I kept adding 1, 100, 1000, and even 10 000, and it wasn’t working.

I had to add an even smaller number. 0.01 did the trick for me.

Thank you so much for your help.

Also, use set timer with loop checked to add the value (that way speed is not dependent on framerate). And reset the value when it exceeds 1.0 to 0.0

1 Like