+4 votes

I want to transform a current implementation of state machine and use the new plugins API.

It works like this:

  • StateControllerNode

    • StateNode 1
    • StateNode 2
    • StateNode 3

In the StateControllerNode you can define the target node you want to control, so you can get access to it by using just a variable from the state nodes.
In the StateNode you can create a custom script wich will extend from StateNode. Inside you get access to callback functions like enterstate(), exitstate(), process_state(delta), etc.

I checked the current plugin demos, but the closest thing to this is the HeartNode demo, but in that plugin the script that is attached to the node is always present, and is a direct reference to the script .gd file, so if the user changes the content of the node's script, all instances of the node will also be changed.

I want to have a "virtual" ScriptNode class with the base implementation that users can extend and override.

I know this is possible by writing a custom C++ module, but I want to do it using the plugin system.

in Engine by (16 points)

I don't think that kind of architecture is possible with the current plugin system (I can be wrong, though; I'm exploring it too, haha).

But what I think you can do is, instead of adding the StateNode as a custom type, you only allow his instancing on the scene through a plugin GUI (something like Path2D node, in which when you click on the node, buttons appear on the upper tab of the 2D editor - in your case, when you click on the StateControllerNode, a button to add States appear). With that, is possible for you to instance inside the ControllerNode a StateNode.scn you create yourself (I'm imagining something like an empty node as a root, and as his child a node with a script attached to it, with all the StateNode methods you want the user to have access; it will be a 'composing over inheritance' architecture).

I'm not adding this option as an answer because people may overlook your question if it has already an answer, and I can possibly be wrong thinking that what you said is not possible. But at least this is a possible design for your plugin, although you will have some more work to do with the interfaces and stuff.

Note: you can surround code in grave accent characters --http://godotengine.org/qa/1016/how-to-write-underscore-_-in-comments

Thanks for your answer. Yeah I think I can do that for now.
I'll try to find another way. I think that for now I can have only the StateController node and make the users add a simple Node as a child of it and add a custom script that extends "res://addons/state_controller/state.gd".
Its not the best solution but it works fine.

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 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.