- Edited
Hi,
New to Godot and have a question relating to instantiating Pack Scenes in .NET code and then be able to use the specific type that it is. I'm playing around building a football/soccer match engine.
In this case, I have a Pitch which manages the match engine. Then I have a "Baller" scene which represents a player. The match engine will spawn 22 of these on load.
This is my code to instantiate a Baller:
Vector3 pos = new Vector3(fieldCenter.X, 1.0f, fieldCenter.Z) + formation[i];
var player = BallerScene.Instantiate() as Baller;
AddChild(player);
player.Team = 1;
if (i == 0)
player.IsGoalkeeper = true;
player.FormationPosition = pos;
player.GlobalTransform = new Transform3D(Basis.Identity, pos);
team.Add(player);
The trouble is that player
is null because it can't case the CharacterBody3D
to a Baller
(even though it extends from it).
I want to be able to use the Baller
type to then use the properties of Baller e.g., IsGoalkeeper
.
How do I do this in .NET?
Thanks!
EDIT
I've tried adding [GlobalClass]
to my Baller.cs
script and while this in recognised in Godot, it doesn't allow me to cast still.