How do I SetTextureOffset in LWRP?
Hello. I'm trying to offset the texture and I'm using the example script from here : https://docs.unity3d.com/ScriptReference/Material.SetTextureOffset.html I'm using the light weight render pipeline / universal render pipeline. It doesn't work. I get no errors, but nothing happens at all. I just want to know what I need to type to offset the texture instead.
using UnityEngine;
public class Example : MonoBehaviour
{
// Scroll main texture based on time
float scrollSpeed = 0.5f;
Renderer rend;
void Start()
{
rend = GetComponent<Renderer> ();
}
void Update()
{
float offset = Time.time * scrollSpeed;
rend.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
}
}
EDIT: It doesn't seem to work with any of the shaders that are listed in the folder "Lightweight Render Pipeline". However, if I pick another folder "Unlit > Textured" it works fine. All the other shaders I can select display a purple colour (because I guess they don't work with the LWRP).
Does your material shader actually have an offset property?
Yes. I'm using the default LWRP unlit one (but I've tried a handful of different LWRP shaders). If I change the offset in the inspector, it works perfectly. I just have no clue how to figure out how to do it in code.
Just for clarity, I'm basically starting from a fresh project with LWRP Template and have no code that could be intefering. Which is why I'm so confused the official example script doesn't work.
It's possible that unity optimizes away the offset part of the shader if you leave the default offset values. Have you tried setting them to any other value than 0?
Answer by marcozakaria · Nov 26, 2019 at 10:00 AM
use : material.SetTextureOffset("_BaseMap", newOffset);
"_MainTex" will not work instead "_BaseMap".
Your answer
Follow this Question
Related Questions
error CS0246 1 Answer
how can i use render priority with hdrp? 0 Answers
Light not instantiate after a time 0 Answers
how do i take whats on one UI canvas and make it apear on another in real time(for a card game) 0 Answers
Unity opens but it won't show anything?,Unity opens , but it doesn't show anyting? 0 Answers