From d255d613194e72b7a6084fd0ed28c94f933fd112 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 7 Jun 2024 04:56:02 +0200 Subject: [PATCH] fix the you are not the main thread and the editor is currently in a play mode errors --- .../Private/SGTracking/SGGloveTracker.cpp | 8 +++++++- .../SenseGloveTracking/Private/SGTracking/SGXRTracker.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/SenseGloveTracking/Private/SGTracking/SGGloveTracker.cpp b/Source/SenseGloveTracking/Private/SGTracking/SGGloveTracker.cpp index aa03246b..a1c7aa39 100644 --- a/Source/SenseGloveTracking/Private/SGTracking/SGGloveTracker.cpp +++ b/Source/SenseGloveTracking/Private/SGTracking/SGGloveTracker.cpp @@ -128,7 +128,13 @@ UWorld* USGGloveTracker::FImpl::GetWorld() } } - if (!IsValid(World)) + /// NOTE + /// IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting: + /// "You are not on the main thread." + /// !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid + /// EngineScriptHelpers::CheckIfInEditorAndPIE emitting: + /// The Editor is currently in a play mode. + if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld)) { UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem()}; if (IsValid(UnrealEditorSubsystem)) diff --git a/Source/SenseGloveTracking/Private/SGTracking/SGXRTracker.cpp b/Source/SenseGloveTracking/Private/SGTracking/SGXRTracker.cpp index 2ac70407..08164e64 100644 --- a/Source/SenseGloveTracking/Private/SGTracking/SGXRTracker.cpp +++ b/Source/SenseGloveTracking/Private/SGTracking/SGXRTracker.cpp @@ -538,7 +538,13 @@ UWorld* FSGXRTracker::FImpl::GetWorld() } } - if (!IsValid(World)) + /// NOTE + /// IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting: + /// "You are not on the main thread." + /// !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid + /// EngineScriptHelpers::CheckIfInEditorAndPIE emitting: + /// The Editor is currently in a play mode. + if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld)) { UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem()}; if (IsValid(UnrealEditorSubsystem))