Monkey-patching the original CharacterBody3D template script

My current goal: Monkey-patching the original CharacterBody3D template script to replace CharacterBody3D Input Handling in Godot 4.4

Godot Version

4.4

Question

I would like to know if there is any way to continue development using CharacterBody3D template script or It’s something completely not ready and is not made for further use: I would like to override the default script movement, replacing it by WASD keys and continue thinking on how I would create separate sub-nodes to improve the original. This is mostly to depend on official code and see how much can be done with the original template code.

Currently I’m baffled on how could I use another script to change local variables such as input_dir and direction. The only way I know is overwriting the entire func _physics_process by extending character_body_3d.gd. Which is surely not what would one want. So how do we change these variables (input_dir and direction) by giving control to other script, using another gd script?

CharacterBody3D .gd

This can be done by editing the “ui_*” actions into your own custom actions as determined by the project setttings Input Map tab.

You could bring those variables into the class body, though the order of which scripts are executed could result in a extra one-frame delay for your inputs → velocity. So I wouldn’t recommend a control by child nodes approach.

Why not use inheritance? Do you have a specific project in mind or some sort of limitation you have run into?


In total I would recommend changing the actions in the script to ones you’ve defined in the input mapper. Keep the input near their effects

1 Like

What are you hoping to accomplish by doing this?