X Tutup
Skip to content

Add recording_signals to MissingNode, and rename MTVIRTUAL to DEBUG_VIRTUAL#105449

Merged
Repiteo merged 2 commits intogodotengine:masterfrom
raulsntos:MissingNode/recording_signals
Oct 10, 2025
Merged

Add recording_signals to MissingNode, and rename MTVIRTUAL to DEBUG_VIRTUAL#105449
Repiteo merged 2 commits intogodotengine:masterfrom
raulsntos:MissingNode/recording_signals

Conversation

@raulsntos
Copy link
Member

@raulsntos raulsntos commented Apr 16, 2025

Allows connecting unknown signals to MissingNode so they aren't lost when the Node type is missing.

I found myself in need of this when implementing the upgrading tool for C#. We remove the scripts and replace Nodes and Resources with MissingNode and MissingResource since the classes aren't registered yet. This preserves the properties but the signal connections are lost, so this PR implements something like recording_properties but for signals.

Update: Now it also renames MTVIRTUAL to DEBUG_VIRTUAL (context: #105449 (comment)).

@raulsntos raulsntos added this to the 4.x milestone Apr 16, 2025
@raulsntos raulsntos requested review from a team as code owners April 16, 2025 04:47
Comment on lines +49 to +51
#ifdef DEBUG_ENABLED
virtual Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0) override;
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why this is DEBUG_ENABLED, when the rest of this class isn't guarded similarly.

I found that Object::connect is defined like this:

// When in debug, some non-virtual functions can be overridden for multithreaded guards.
#ifdef DEBUG_ENABLED
#define MTVIRTUAL virtual
#else
#define MTVIRTUAL
#endif // DEBUG_ENABLED
        MTVIRTUAL Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0);

So we're kind of abusing the system here by using connect as a virtual method. It seems it's not meant to be, and was just made virtual for debug builds to add thread guards.

Maybe it's fine to (ab)use the system this way for something that's also fairly specific to debug/editor functionality.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time you mentioned that overriding connect was a big no-no. I don't remember for what reason, likely for adding an editor warning onto a Node. Meanwhile here is the rest of the engine doing so nonchalantly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall the details, but yeah committing a crime against core architecture for the sake of warnings is a not great. I assume this was also done in a more frequently used node or resource type which could have an impact on performance of connecting signals.

Here, this is done on MissingNode which is only used in case of reloading extensions in the editor, so it's not a hot path. And more importantly, the purpose is to allow converting C# scripts from the mono module to C# classes compatible with the dotnet module, so the stakes are different :)

It's still a hack, but not all hacks are created equal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably OK, given what this node is used for.

But it does make the MTVIRTUAL in object.h kind of poorly named, and the comment where it's defined only partially accurate. I don't know if it make sense to do in this PR, but it may be worth renaming MTVIRTUAL to DEBUG_VIRTUAL (or similar) and updating that comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, let's rename MTVIRTUAL to DEBUG_VIRTUAL in this PR and update the comment @raulsntos

@raulsntos raulsntos force-pushed the MissingNode/recording_signals branch from 118e700 to 802f952 Compare October 6, 2025 05:18
Allows connecting unknown signals to MissingNode so they aren't lost when the Node type is missing.
@raulsntos raulsntos force-pushed the MissingNode/recording_signals branch from 802f952 to 09ad9e5 Compare October 9, 2025 20:18
@raulsntos raulsntos changed the title Add recording_signals to MissingNode Add recording_signals to MissingNode, and rename MTVIRTUAL to DEBUG_VIRTUAL Oct 9, 2025
@akien-mga akien-mga modified the milestones: 4.x, 4.6 Oct 9, 2025
@Repiteo Repiteo merged commit dd3b17d into godotengine:master Oct 10, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 10, 2025

Thanks!

@raulsntos raulsntos deleted the MissingNode/recording_signals branch October 10, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup