Godot 4.4 animation
Hello,
I Needed an animation where i didn’t know some position till runtime , so i figured i can build animation from code and its playing fine
Once i create animation from code i cannot play any other animation i keep getting “No animation in cache.
No animation in cache.
No animation in cache.
No animation in cache.
No animation in cache.
No animation in cache.
No animation in cache.
No animation in cache.
No animation in cache.”
Bellow is the code
animationPlayer.SpeedScale = 1;
animationPlayer.RootNode = GetPath();
AnimationLibrary aniLib = new AnimationLibrary();
var turnAnimation = new Animation()
{
Length = 0.4f,
LoopMode = Animation.LoopModeEnum.None
};
//
int positionTrack = turnAnimation.AddTrack(Animation.TrackType.Value);
turnAnimation.TrackSetPath(positionTrack, ".:position");
int rotationTrack = turnAnimation.AddTrack(Animation.TrackType.Value);
turnAnimation.TrackSetPath(rotationTrack, ".:rotation");
for (int i = 0; i <= CardDealSpeed; i++)
{
float moveWeight=1f / CardDealSpeed *i;
var positionTmp =initialPosition.Lerp(targetPosition, moveWeight);
//var positionTmp =initialPosition.Lerp(targetPosition
if (i < Math.Ceiling((decimal)CardDealSpeed / 2))
{
positionTmp = new Vector3(positionTmp.X, positionTmp.Y + (0.1f * i), positionTmp.Z);
}
else
{
positionTmp = new Vector3(positionTmp.X, positionTmp.Y + (0.1f * (CardDealSpeed-i)), positionTmp.Z);
}
turnAnimation.TrackInsertKey(positionTrack, i * 0.1f, positionTmp);
turnAnimation.TrackInsertKey(rotationTrack, i * 0.1f, new Vector3(-2*i,0,0));
}
var animlibs = animationPlayer.GetAnimationLibraryList();
var exist = animlibs.FirstOrDefault(x => x == "Procedural");
if (exist == null)
{
aniLib.AddAnimation("DealCard", turnAnimation);
animationPlayer.AddAnimationLibrary("Procedural", aniLib);
}
else
{
var proceduralAnimLib = animationPlayer.GetAnimationLibrary(exist);
proceduralAnimLib.AddAnimation("DealCard", turnAnimation);
}
It doesnt matter if i add it from editor or code the error is the same .
Question
Any help would be greatly valued