3
\$\begingroup\$

I'm thinking of something similar to Unity, where GameObjects have their boot state and their runtime state, where you can change the runtime state in the editor during game play.

Godot is a distinctly different, but in some ways similar, engine. I'm wondering if I can take a node and monitor, or tweak, its parameters during gameplay, like I can in Unity? I'm having a hard time finding information on this.

\$\endgroup\$

3 Answers 3

6
\$\begingroup\$

You can do so, although Godot's behavior is slightly different to Unity and I'd suggest trying it in a small test project before you unintentionally change an actual working project.

The functionality you're looking for is hidden in the Scene Tree inspector of the editor, i.e. the "Scene" tab. Once your project is running and the editor is connected, it will show two new buttons/tabs right above the scene tree:

  • Local shows your editor state, i.e. your boot state. You can change everything while the project is running and values will be adjusted immediately (this also includes changes within the editor's main view, e.g. modifying tile maps).
  • Remote shows your the project's running scene tree/state. You can select and modify the nodes in this tree, which is your runtime state. Note that your main editor window will always stay in the Local state, but if you click on any node in the Remote scene tree, your Node Inspector will show the selected node.

The scene tree with visible "Local" and "Remote" toggle.

I've recorded a short clip from an experimental project of mine to demonstrate this (don't mind Samus Aran running around, this is just for testing instead of developer art).

Note: The inspector will only show exported variables. In Godot 3.x, you do this by preceding them with the keyword export. The GDScript exports documentation has more information and a lengthy example of the various options. Fortunately, most of the time one of these two is good enough:

export var some_variable_name = 5
export(int) var some_variable_name 

You would replace some_variable_name with your actual variable name and depending on which version you go with, either replace 5 with your reasonable starting value or replace int with your actual type being used.

In Godot 4, you use the @export keyword instead. The documentation for that version can be found here.

\$\endgroup\$
3
  • \$\begingroup\$ I feel like your answer has a better basis than mine. Rather than splitting the info between the two answer posts, would you like me edit to include a slimmed down version of my content directly in your answer? \$\endgroup\$
    – Pikalek
    Feb 10, 2023 at 16:51
  • \$\begingroup\$ @Pikalek Don't let me stop you, that's the whole purpose of the edit function. 👍 \$\endgroup\$
    – Mario
    Feb 13, 2023 at 8:50
  • \$\begingroup\$ Done, feel free to tweak the formatting, etc as desired. I tried to refactor my content down to the bare minimum as I edited it in. I'll leave mine up a for a while in case you want to add anything else from it. \$\endgroup\$
    – Pikalek
    Feb 13, 2023 at 15:20
1
\$\begingroup\$

I believe they are asking if you can edit in the editor at runtime like Unity does. Unity plays the runtime back in the editor and the game window at the same time, and you can change things like you would in the editor during play testing. So, no, that isn't how Godot does it's play-testing mode. You can only edit in the inspector and the editor doesn't reflect the runtime and game preview doesn't change the editor view in real-time.

\$\endgroup\$
0
\$\begingroup\$

I'm not familiar with Unity's workflow, but from your description it sounds like a GDScript export will do what you want. From the official description:

In Godot, class members can be exported. This means their value gets saved along with the resource (such as the scene) they're attached to. They will also be available for editing in the property editor. Exporting is done by using the export keyword:

extends Button

export var number = 5 # Value will be saved and visible in the property editor.

An exported variable must be initialized to a constant expression or have an export hint in the form of an argument to the export keyword (see the Examples section below).

One of the fundamental benefits of exporting member variables is to have them visible and editable in the editor. This way, artists and game designers can modify values that later influence how the program runs ...

The official documentation (linked at the start of the answer) has a lengthy example of the various options - so lengthy that it may be discouraging. Fortunately, most of the time one of these two is good enough:

export var some_variable_name = 5
export(int) var some_variable_name 

You would replace some_variable_name with your actual variable name and depending on which version you go with, either replace 5 with your reasonable starting value or replace int with your actual type being used.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for your time, but what I'm specifically interested in is modifying these fields in a running scene, not before starting the game. This doesn't really address my question. \$\endgroup\$ Feb 10, 2023 at 18:01
  • \$\begingroup\$ Yes I understand that aspect. If you want to use the Godot's editor interface to change the values of custom variables, you need to declare them as export. Mario's answer shows how to use the editor to change the variables - my answer shows how to get the variables to show up in the editor. \$\endgroup\$
    – Pikalek
    Feb 10, 2023 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .