diff --git a/GDTask/src/PlayerLoopRunner/GDTaskPlayerLoopRunner.cs b/GDTask/src/PlayerLoopRunner/GDTaskPlayerLoopRunner.cs index 4cdf1a9..a9f104f 100644 --- a/GDTask/src/PlayerLoopRunner/GDTaskPlayerLoopRunner.cs +++ b/GDTask/src/PlayerLoopRunner/GDTaskPlayerLoopRunner.cs @@ -77,6 +77,7 @@ public static GDTaskPlayerLoopRunner Global { get { + RuntimeChecker.ThrowIfEditor(); if (s_Global != null) return s_Global; var newInstance = new GDTaskPlayerLoopRunner(); diff --git a/GDTask/src/RuntimeGuard/RuntimeChecker.cs b/GDTask/src/RuntimeGuard/RuntimeChecker.cs new file mode 100644 index 0000000..3386ae9 --- /dev/null +++ b/GDTask/src/RuntimeGuard/RuntimeChecker.cs @@ -0,0 +1,13 @@ +using System; +using Godot; + +namespace GodotTask.Internal; + +internal static class RuntimeChecker +{ + internal static void ThrowIfEditor() + { + if(!Engine.IsEditorHint()) return; + throw new InvalidOperationException("Calling any GDTask API under editor is not supported."); + } +} \ No newline at end of file diff --git a/GDTask/src/Triggers/AsyncTriggerExtensions.cs b/GDTask/src/Triggers/AsyncTriggerExtensions.cs index 0e1e1ad..1701a53 100644 --- a/GDTask/src/Triggers/AsyncTriggerExtensions.cs +++ b/GDTask/src/Triggers/AsyncTriggerExtensions.cs @@ -1,5 +1,6 @@ using System; using Godot; +using GodotTask.Internal; namespace GodotTask.Triggers { @@ -27,6 +28,7 @@ internal static T GetChild(this Node node, bool includeRoot = true) internal static T GetOrCreateChild(this Node node) where T : Node, new() { + RuntimeChecker.ThrowIfEditor(); T child = GetChild(node); if (child == null) child = CreateChild(node);