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:
On BeginPlay, I create a Dynamic Material instance of my material and set it as the material of the mesh in my level.
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.
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…
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.
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.
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.
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.