From a91a3d01f849ba3a7c1615003f8f11ca824d3d58 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Fri, 2 Sep 2022 22:31:56 +0200 Subject: C#: Create script instance of reloaded scripts even if they're not tools Scripts that are instantiated at some point will always be recreated if they ever become placeholders to prevent non-tool scripts instantiated manually by users to become placeholders, if they do become placeholders due to errors that prevent instantiation (such as a missing parameterless constructor) these scripts will also be recreated replacing the temporary placeholder. If a script is marked as a tool but becomes a non-tool script in a rebuild, the script will become a placeholder and will no longer be considered applicable to be replaced by an instance since the user explicitly removed the Tool attribute. --- .../mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/mono/glue') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs index 3884781988..092724a6b1 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs @@ -130,7 +130,6 @@ namespace Godot.Bridge { // Performance is not critical here as this will be replaced with source generators. Type scriptType = _scriptTypeBiMap.GetScriptType(scriptPtr); - var obj = (Object)FormatterServices.GetUninitializedObject(scriptType); var ctor = scriptType .GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) @@ -151,6 +150,8 @@ namespace Godot.Bridge } } + var obj = (Object)FormatterServices.GetUninitializedObject(scriptType); + var parameters = ctor.GetParameters(); int paramCount = parameters.Length; -- cgit v1.2.3