0 votes

You can find this sample project on github.

My intent is to create an Actor and Models scenes, which implement Type Object Pattern. In few words: an Actor is a container with common logic (say, movement, actions etc), Model should define the looks.

In the sample project there are Actor scene and class, Model1 and Model2 scenes with corresponding classes. Models has Sprite child node to distinguish between them. Also models inherit from ModelInterface (I really miss interface feature from other oop programming languages) and have an init method.

In res://Model folder there is a ModelFactory class to create models, base on some parameter (say their type id). Actor is a tool and I want to switch its model in the editor. Actor has current_model_type variable and corresponding setter, which calls ModelFactory to create a new model, runs its init method and attaches it to Actor.

The problem is, that in editor I get an error:
res://Actor/Actor.gd:27 - Invalid call. Nonexistent function 'init' in base 'Node2D (Model1.gd)'.
but when running the project everything works as intended. Should I load the scenes in a different way?

Thanks for any help!

Godot version 3.3.2
in Engine by (19 points)

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.