Hi, I'm coming over from Unity, just trying to get my feet on the ground with C# in Godot 3.2. I've created a simple script for my player character:
using Godot;
public class FirstPersonPlayer : KinematicBody {
[Export] private Camera myCam;
}
Now, in Unity, the inspector would show you a field in the script variables which allows you to assign a camera. At first glance, Godot seems to do the same:
However, once I click on the dropdown...
... I get a rundown of ALL the stuff Godot knows. Not just cameras. Okay, that was irritating, but at the very bottom it says "load", which allows me to select a file. Except that the camera which is in my scene is not in its own file. It's just a sub-node.
"Okay", I thought, "next try. Let's just take the camera node from the scene tree and draaaag it over into the slot"... Except that I can't do that either: the inspector immediately switches to the camera, and I can't seem to lock it.
So basically: Is getNode(path)
really the only way to get a reference to an object in the scene?
In Unity, even using getComponent()
(which fetches a script on the same game object) is generally frowned upon, and iterating over the children is discouraged even more because it tends to make game code very brittle and creates implicit dependencies, whereas editor-exposed fields are at least explicit.
Am I missing something? Or is godot philosophy simply different here?