Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animate UV Offset in Unity Animation Timeline
#3
(05-25-2023, 09:45 AM)_Aka_ Wrote: Hi
All the material parameters are internally stored in an array. It seems that the animator does not show members of type Array.
The solution would be then to create a script that will act as a middle man between the animation and the module:
The script will for example have a float V offset value, editable by an animation. The script will every frame apply that value to yourModule.MaterialSettings[yourMaterialIndex].UVOffset.y
Did this help?
I wrote the following script to try to control the value, but I seem to be getting an error saying that MissingComponentException, there is no Meshrender attached to the Game Object. 

Code:
using UnityEngine;

public class MaterialOffsetController : MonoBehaviour
{
    public float vOffset;
    public GameObject river;
    public int materialIndex;

    private MeshRenderer meshRenderer;

    private void Start()
    {
        // Get the MeshRenderer component from the specified GameObject
        meshRenderer = river.GetComponent<MeshRenderer>();
    }

    private void Update()
    {
        // Update the material's UVOffset.y value based on the vOffset value
        Material[] materials = meshRenderer.materials;
        if (materialIndex >= 0 && materialIndex < materials.Length)
        {
            Material material = materials[materialIndex];
            Vector2 offset = material.GetTextureOffset("_MainTex");
            offset.y = vOffset;
            material.SetTextureOffset("_MainTex", offset);
        }
    }
}

I am setting the script on a empty parent game object and selecting the Curvy Spline Generator as the GameObject. I am pretty sure I am not access the property value correctly.
Reply


Messages In This Thread
RE: Animate UV Offset in Unity Animation Timeline - by sam_bond - 05-25-2023, 10:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Best way to duplicate a spline with an offset Kapistijn 8 1,345 04-12-2026, 03:18 PM
Last Post: _Aka_
  Unity 6 issues Moonbo 4 1,152 11-21-2025, 12:07 PM
Last Post: _Aka_
  Absolute offset for shape extrudes rickgplus 1 1,442 03-21-2025, 12:37 PM
Last Post: _Aka_
Information New free asset: Converter For Unity Splines _Aka_ 20 11,976 07-19-2024, 05:15 PM
Last Post: _Aka_

Forum Jump: