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
  Additional offset to Follow behaviour Ayyappa 1 1 3 hours ago
Last Post: _Aka_
Information New free asset: Converter For Unity Splines _Aka_ 5 18 04-25-2024, 11:11 AM
Last Post: _Aka_
  Using Unity's SplineContainer in Curvy Splines dlees9191 3 15 02-26-2024, 09:49 AM
Last Post: _Aka_
  Unity 2021.2 Overlay System nehvaleem 5 17 12-15-2023, 10:09 AM
Last Post: _Aka_

Forum Jump: