I’m trying to make a cutscene system with custom resources but when I try to use my code to run an animation it is sending an error message, which appears to be saying the animation does not exist, but in the animation editor it does show up, with the same name.
using Godot;
using System;
using System.Collections;
using System.Threading.Tasks;
public partial class mainChara : Node2D
{
[Export] public Camera2D Camera;
[Export] public int CameraLimitLeft = -152;
[Export] public int CameraLimitTop = -114;
[Export] public int CameraLimitRight = 152;
[Export] public int CameraLimitBottom = 114;
[Export] public PackedScene SpeechBox;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Camera.LimitLeft = CameraLimitLeft;
Camera.LimitTop = CameraLimitTop;
Camera.LimitRight = CameraLimitRight;
Camera.LimitBottom = CameraLimitBottom;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public async void RunCutscene(CutsceneResource Resource)
{
for(int i = 0; i < Resource.Actions.Length; i++)
{
if(Resource.Actions[i] is DialogueResource)
{
DialogueResource Dialoge = Resource.Actions[i] as DialogueResource;
await TextBox(Dialoge);
}
else if(Resource.Actions[i] is CutsceneAnimation)
{
CutsceneAnimation Animation = Resource.Actions[i] as CutsceneAnimation;
PlayAnimation(Animation);
}
else
{
GD.PrintErr("Error " + Resource.CutsceneName + " at index " + i + " is of type " + Resource.Actions[i].GetType() + " which is invalid.");
}
}
return;
}
public async Task TextBox(DialogueResource action)
{
Node2D Object = (Node2D)SpeechBox.Instantiate();
Object.Set("WhatToSay", action.dialogue);
Object.Set("FaceSprite", action.FaceSprite);
Object.Set("FaceSprite2", action.FaceSprite2);
Object.Set("TextSound", action.TextSound);
Object.Set("Font", action.Font);
Object.Name = "SpeechBox";
AddChild(Object);
while (GetNodeOrNull("SpeechBox") != null)
{
await ToSignal(GetTree().CreateTimer(0.001), "timeout");
}
return;
}
public IEnumerator PlayAnimation(CutsceneAnimation action)
{
action.AnimPlayer.Play(action.AnimationName);
return null;
}
}
Are you sure the AnimationPlayer you target is the right one ?
With your script i cannot tell what contains your action parameters line 69.
Try printing action.AnimPlayer just before the play call.
The name of your animation is right so problems is somewhere else.
using Godot;
using System;
using System.Collections.Generic;
[Tool]
public partial class CutsceneResource : Resource
{
[Export] public string CutsceneName; //Used so the debug code works properly
[Export] public Resource[] Actions = new Resource[0];
}
The issue is probably arising from the CutsceneAnimation resource
using Godot;
using System;
using System.Collections.Generic;
[Tool]
public partial class CutsceneAnimation : Resource
{
[Export] public AnimationPlayer AnimPlayer;
[Export] public string AnimationName;
}
Can you send us the .tscn file containing the scene where this occurs ? With it we can check if the name is correctly spelled and if your resource content match the AnimationPlayer.
It doesn’t let me upload .tscn files, but I was planning on settitng up a github repo of the project, I will do that today if I can, but if I can’t do it today it won’t be until at least sunday that I can
Ok so it’s missing the project.godot file but figured out how to launch it.
I have used godot 4.2.1 for it just to quickly know and i cannot compile the game because of this error :
GD0107: Types not derived from Node should not export Node fields C:\project_path\UndertaleFangameFramework\Scripts\Custom Resoruces\CutsceneAnimation.cs(8,37)
So maybe in Godot 4.1 you don’t get error but the problem still here, You cannot set a node type object in a resource as resource are not node themself.
EDIT :
Ok so indeed, it’s the fact that your resource contains a Node. I have find a workaround :
In your CutsceneAnimation resource I have changed the line with the node by this one (line 8) : [Export] public string AnimPlayerPath;
And in mainChara.cs where you start the animation change the line by this one (line 71) : GetNode<AnimationPlayer>(action.AnimPlayerPath).Play(action.AnimationName);
After that the only thing you need to change is in sans area2d resources you defined to the Anim Player Path to /root/TestRoom/Toriel/Sprite2D/AnimationPlayer
And everything work as expected.