Godot Version
4.5.1
Question
Ok so I need some help. I am just learning gdscript and it seems very intuitive so far and I don’t mind it. However I come from a C++ and C# background so I’m used to using object oriented programming, classes and polymorphism. I am moving my current game from Unity over to GODOT. I have looked and googled many times how to do this so please bare with me on me explaining the situation.
First my final product : I am making a enemy spawn point in my game. I have multiple enemies in the game to spawn. I want to be able to make a spawn point node and pass in another scene that can take which ever enemy I choose. So I would some type of chiefobject and all the enemies would derive from this. Then in the scene I would load in the chief object class and make it a variable and export it out to the scene so I can just drag and drop the chosen enemy into it’s place.
Where I am at:
So far I have learned how to make a class and child classes. I have learned about setters and getters and all the object oriented things. I read through the documentation on the site. Here is an example of what I have so far for my chief object. This is just a test so don’t judge to harshly.
This code is in it’s own gdscript called ChiefObject.
class_name ChiefObject extends Node2D
var m_isActivated : bool = true
var isActivated : bool :
get:
return m_isActivated
set(value):
m_isActivated = value
Next class : So I took this and want to derive a Destructables Class from this so this is what I made. Just basically a blank template for now. It is in its own gdscript file.
class_name DestructableObject extends ChiefObject
Current position :
So currently I am at this juncture. I have the spawn_point node2d scene and a node in that scene. Script wise I load in the chief object and export it out so it can be set when I choose the given enemy. Now the code in _ready was for testing purposes to see if I can actually access the class members. Which now looking at it I am not sure how private, public and protected members work, so I will have to look into that.
I now have another Node2D scene called roller which is an enemy. I derived that from DestructableObject. This is just a blank class set up with the roller scene.
extends Node2D
@export var CO = preload("res://Scripts/ChiefObject.gd")
func _ready() -> void:
var test = CO.new()
test.isActivated = false
With this all said I added the spawn_point scene to the main scene where everything runs and tried to assign the ChiefObject var in the spawn_point scene with this roller scene but it does not let me set it.
With this I am believe I am thinking about this all wrong but am not sure how to continue. If anyone could be of any assistance that would be great. I am just looking for the best way to use this type of polymorphism in the game because I use it all the time in the unity project. I just hope I don’t have to go back to unity lol.

