Using Godot 4, following a tutorial but the tutorial is in GDScript. It is hard to find one for C# so I am trying to convert it as I go.
I made a scene called Coin and I have a scene called Main which is my main scene.
I want to instantiate a coin onto my scene.
Here's the GDScript:
var c = coin_scene.instantiate() add_child(c) c.someprop = somevalue
This is my C# code:
[Export] public PackedScene CoinScene; // In my Main scene, I drag the coin.tscn onto it // Ready method: var coin = CoinScene.Instantiate(); AddChild(coin); // This adds the coin to my scene but at 0,0 ie default. coin.someprop = x // Error since `coin` is not an instance of `coin.cs`
coin.cs file is a script attached to my coin scene. However I can't find a way to access it.
I have seen some people say you can just cast it, but it just becomes
null if I do
var x = coin as coin;. The underlying type of the coin object seems to be Node2D even though the Instantiate() method returns a
If anyone could shed some light on the hierarchy of what exactly is going on here it'd be appreciated, as resources for C# are incredibly rare.