I have an array of AABB box classes I defined (just has 4 floats in it) and when I try changing its values in the animation timeline it’s as if I’m changing it normally, so it can’t change with the animation.
I have the same question.
Obviously it’s not possible to add array properties via the Animation window, so I tried to add the property via script like so:
clip.SetCurve(
relativePath: string.Empty,
type: typeof(SplineAnimation),
propertyName: "attachPoints.Array.data[0].curveParameter",
curve);
However, this shows up as a missing property in the animation window, even though the serialized data of the AnimationClip asset looks ok:
The SetCurve documentation states that it is possible to animate the object reference values of the materials array in the renderer components. Theoretically, this would mean that is should be possible to do the same thing with other arrays. But in fact, the materials array accessor seems to be some special case in the animation system and doesn’t apply for other types of arrays.
If anyone has more information on this, I would be very interested. Also I would like to know if it would be possible for Unity to add this feature or if there is something completely preventing it from ever working.
Hello guys, did you figure out in the end? I am stuck now with the same problem
Bump. I’m here in 2021 trying to find the same answer. I’m trying to animate variables in an array and it won’t record anything.
I can’t say I’m too surprised that it doesn’t work with a collection of structs, but an array of structs (or any other variable) should be base enough types to work.
Yes
Same problem im learning unity editor and i want my serialized property fields which are assigned to Lists of objects of types like float,int,color,texture2d and the problem is Animation window doesn’t see them as properties which i could animate. When its simple type eg. public Color color; only then its exposed in the animation window. How to go about it then?
It’s impossible as far as I’m aware.
What is possible is :
- Hardcode N properties instead of an array.
- Instead of serializing the array, use N children gameobjects, each with a component. You can use GetComponentsInChildren from the main script to get the array
Bump. Is it planned for future? I don’t want to hardcode an array
There’s a way, and may be the current only way to animate classes in array. If you use [SerializeReference]
instead of [SerializeField], you can animate every element in the list/array.
Here’s an example:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class MyRefClass
{
public int intField;
public bool boolField;
public Vector3 v3Field;
}
public class SerializedReferenceArrayAnimationTestScript : MonoBehaviour
{
[SerializeReference] private List<MyRefClass> myRefClassList; // I think you can't animate a struct
private void Reset()
{
myRefClassList = new();
myRefClassList.Add(new MyRefClass());
myRefClassList.Add(new MyRefClass());
myRefClassList.Add(new MyRefClass());
}
}
If you open Animation window and start Recording, and adjust the field values in MyRefClass in myRefClassList, you could see that it records individual array data into the animation clip.
However, it’s very fragile, so use it carefully.