- Edited
Hi guys, I try to extend godot class functionality but Inheritance fails in C#
//Extend AnimationPlayer Class
public class MyPlayer:AnimationPlayer
{
public bool First=false;
public string OriginalName="";
public void MyOwnMethod()
{
.
.
.}
}
//Where I use extended class
public class SceneScript : Control
{
public MyPlayer Player;
public override void _Ready()
{
//Try 1:
Player=(MyPlayer)GetNode("something");//Try 1: Fails with message "Specified cast is not valid",so I removed it
//Try 2:
Player=GetNode("something") as MyPlayer;//Building doe snot show any error here
Player.Connect("animation_finished",this,nameof(Task));//also here fails with same message "Object reference not set to an instance of an object"
}
}
I know the meaning of errors but I don't know a solution, Please any one have solution for this?
//========================================================
//============My current solution is===========================
//========================================================
public class MyPlayer
{
public AnimationPlayer Player;
public bool First=false;
public string OriginalName="";
public void MyOwnMethod()
{
.
.
.}
}
public class SceneScript : Control
{
public MyPlayer ExPlayer=new MyPlayer();
public override void _Ready()
{
ExPlayer.Player=(AnimationPlayer)GetNode("something");
ExPlayer.Player.Connect("animation_finished",this,nameof(Task));
}
}
it woks perfectly but is not what I want.