+1 vote

Hi everyone,

This is my second day of trying out Godot, so here's my noob-question...
Let's say, I want to have some complex instances in my game like a player-character and some NPCs to go along with it. In any other language (C++, Python, Java; you name it...) I would structure my code like this https://ibb.co/CpyzL6C (not conclusive). Creating a lot of classes that inherit from super-classes and using instances of smaller classes as members is how I usually structure my logic.
I'm just quite confused with all the options that Godot offers. Scenes, Scripts, custom Nodes (which seem to be just normal Nodes with your scripts attached to them by default...) - it's just really puzzling to me.
Could someone maybe explain, what all these things are (I mean technically/in-depth, I've read the wiki allready) and when to use which of them.

Best regards,
TheBeautifulOrc

in Engine by (16 points)

1 Answer

+2 votes
Best answer

Godot is object-oriented just like those other languages you named. Nodes provide functionality, and scripts extend that functionality by adding properties (data) and methods (behavior). Scenes (collections of nodes) can inherit from other scenes, and script objects can inherit from other scripts.

So in your example, you would create an Entity scene containing the common nodes and common code that all entities need, then inherit from it to make the player (attaching a camera, for instance) and the npcs. You do this by choosing "New Inherited Scene".

As for scripts, if you have an "entity.gd" script, which begins with extends KinematicBody2D, then in the player you'd start with extends "res://entity/entity.gd" for example (this can be done in the editor when you create the script, or manually).

You can see an example of this in practice here: http://kidscancode.org/blog/2018/01/godot3_inheritance/

On top of all this, you can also define your own custom classes if you wish. See here for details: https://docs.godotengine.org/en/latest/getting_started/scripting/gdscript/gdscript_basics.html#classes

I hope this helps. Your question was very general, so please open another if you have a more specific question about implementation details.

by (22,067 points)
selected by

Thanks for the nice overview and the ressources, you've provided. I'll try out the recomended methods as soon as I can. And I guess, I'll check out your YouTube-channel, too :D

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.