this post was submitted on 30 Jul 2024
17 points (94.7% liked)

Godot

6005 readers
4 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 2 years ago
MODERATORS
 

I am coming from a Unity background and there I just had a component of some custom class in the scene which I could then easily get by calling FindInScene<CustomComponent> or something like that. Not in Godot this doesn't work, because I didn't find a way to get the actual class of an attached script. I always just get GDScript as the class name even though I did specify a custom one.

The information I want to save are things like: where to spawn players, how many laps will this race have, maybe save references to the spawned players, etc.

So how would I save this "meta" information to get by another script in Godot?

EDIT: here is an example: I have a main scene which can load different levels. When loading a level I need to get some information about that level, like: the available spawn points. Inside each level I have a node with a script attached to it that defined class_name LevelMeta and holds the meta information that I need when loading the level. How do I detect this script and the associated meta information?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] domi@lemmy.secnd.me 2 points 4 months ago (1 children)

Do you use C# since you're coming from Unity?

You can use GetNode<CustomNode>() or GetChild<CustomNode>() to find the node you need just like in Unity. CustomNode will be the type of your script or if there is no script attached to your node you can use the builtin types as well (e.g. Node3D).

Once you have the node you want, you can either use Godots builtin functions SetMeta() and GetMeta() to set and get metadata on a node or use the C# way and access the public properties set on that CustomComponent class directly.

I don't use GDScript but I assume you have the same methods available there.

[โ€“] BentiGorlich@gehirneimer.de 1 points 4 months ago

I am using GDScript :(