- Home /
RawImage - Cannot update material's UV offset.
This code is meant to animate the UV on a RawImage component so that it animates. It was working in a 2019 version of Unity. However, updating to 2020.1.15f1 causes the below code to do nothing (without error). From the Inspector view, it doesn't seem like it's changing the material of the RawImage.material. Is this a bug or does the RawImage component have different functionality now?
using UnityEngine;
public class AnimatedImageUV : MonoBehaviour
{
public Vector2 Scroll = Vector2.zero;
private Vector2 _offset = Vector2.zero;
private Material _mat = null;
private UnityEngine.UI.RawImage _image = null;
private void Start()
{
_image = GetComponent<UnityEngine.UI.RawImage>();
_mat = UnityEngine.Object.Instantiate(_image.material);
}
void Update()
{
float time;
time = Time.unscaledTime;
_offset.x = time * Scroll.x;
_offset.y = time * Scroll.y;
_mat.SetTextureOffset("_MainTex", _offset);
_image.material = _mat;
}
}
Answer by Disastercake · Nov 29, 2020 at 06:35 PM
So after some experimenting, I found that the problem was not RawImage component, but the UI/Default shader. It seems that this shader will not actually apply texture offsets (anymore).
I was able to fix it by creating a custom shader (using Amplify Shader Editor). I used a variation of this example: https://wiki.amplify.pt/index.php?title=Unity_Products:Amplify_Shader_Editor/Panner
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to generate different diagonal platforms? 1 Answer
Drawing a straight line between two points with 2D UI 1 Answer
Simple jump code 2D - c# 1 Answer
Distribute terrain in zones 3 Answers