diff --git a/Source/WidgetInteraction/Private/RwthComponent.cpp b/Source/WidgetInteraction/Private/RwthComponent.cpp
index d74511ce66129eb8bfe775f57fc0a20c978d15e2..2685e08e4b8d766cadea1404b1057f71ff6308dc 100644
--- a/Source/WidgetInteraction/Private/RwthComponent.cpp
+++ b/Source/WidgetInteraction/Private/RwthComponent.cpp
@@ -12,7 +12,7 @@ URwthComponent::URwthComponent()
void URwthComponent::Init()
{
- bShowDebug = true;
+ SetVisibility(true);
InteractionDistance = 1000000.0f;
auto input_cmp = dynamic_cast<UInputComponent*>(GetOwner()->GetComponentByClass(UInputComponent::StaticClass()));
@@ -23,6 +23,10 @@ void URwthComponent::Init()
RegisterComponent();
}
+void URwthComponent::SetVisibility(bool visible) {
+ bShowDebug = visible;
+}
+
void URwthComponent::OnFire(bool val)
{
if (val == true)
diff --git a/Source/WidgetInteraction/Private/WidgetInteraction.cpp b/Source/WidgetInteraction/Private/WidgetInteraction.cpp
index 68fd513ee0d0f5f75eb6c45a64710e9e52dc5972..f414d1d36a5e20cf120c0af09964b85bffd57fe5 100644
--- a/Source/WidgetInteraction/Private/WidgetInteraction.cpp
+++ b/Source/WidgetInteraction/Private/WidgetInteraction.cpp
@@ -21,20 +21,26 @@ void FWidgetInteractionModule::ShutdownModule()
void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val)
{
+ //called every Tick()
+
auto worlds = GEngine->GetWorldContexts();
- if (widget_interaction_cmp_ != nullptr) {
- if (widget_interaction_cmp_->IsValidLowLevel() == true) {
- return;
- }
- else {
- widget_interaction_cmp_ = nullptr;
- }
- }
+ for (auto world_context : worlds) {
- for (auto & world_context : worlds)
- {
auto world = world_context.World();
+
+ if (last_world == world && widget_interaction_cmp_ != nullptr) {
+ if (widget_interaction_cmp_->IsValidLowLevel() == true) {
+ continue;
+ }
+ else {
+ widget_interaction_cmp_ = nullptr;
+ }
+ }
+
+ if (world == nullptr)
+ continue;
+
auto player_controller = world->GetFirstPlayerController();
if (player_controller == nullptr)
continue;
@@ -43,6 +49,8 @@ void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val
if (vr_pawn == nullptr)
continue;
+ UE_LOG(LogTemp, Warning, TEXT("OnWorldTickStart called and interaction component will be updated"));
+
FString name = "";
UClass* component_class = UMotionControllerComponent::StaticClass();
@@ -63,15 +71,26 @@ void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val
else {
//if this is a cluster setup we attach it to the flystick
name = TEXT("flystick");
- component_class = UMotionControllerComponent::StaticClass();
+ component_class = UDisplayClusterSceneComponent::StaticClass();
}
auto parent_vec = vr_pawn->GetComponentsByClass(component_class);
- for (auto parent : parent_vec)
- if (parent->GetName() == FString(name))
+ bool success;
+ for (auto parent : parent_vec) {
+ if (parent->GetName() == FString(name)) {
CreateWidgetInteraction(dynamic_cast<USceneComponent*>(parent), vr_pawn);
+ success = true;
+ last_world = world;
+ }
+ }
+
+ if (!success)
+ UE_LOG(LogTemp, Error, TEXT("Failed to load widget asset \"%s\", cannot attach widget interaction component"), *name);
}
+}
+URwthComponent* FWidgetInteractionModule::GetWidgetInteractionComponent() {
+ return widget_interaction_cmp_;
}
void FWidgetInteractionModule::CreateWidgetInteraction(USceneComponent * parent, AVirtualRealityPawn* outer)
diff --git a/Source/WidgetInteraction/Public/RwthComponent.h b/Source/WidgetInteraction/Public/RwthComponent.h
index fb7657858ced622c10fe552e135f056e8f1545d2..d5fda411e5ad92d4c1b3d9ed6f4a6e9fa4c9f0ed 100644
--- a/Source/WidgetInteraction/Public/RwthComponent.h
+++ b/Source/WidgetInteraction/Public/RwthComponent.h
@@ -18,6 +18,8 @@ public:
void Init();
+ void SetVisibility(bool visible);
+
protected:
void OnFire(bool val);
diff --git a/Source/WidgetInteraction/Public/WidgetInteraction.h b/Source/WidgetInteraction/Public/WidgetInteraction.h
index 596d28a989a4467309e488c636c844a1b336c0cf..d1b7bb79aa5179f5b8a93e08283233ad0516feb7 100644
--- a/Source/WidgetInteraction/Public/WidgetInteraction.h
+++ b/Source/WidgetInteraction/Public/WidgetInteraction.h
@@ -7,7 +7,7 @@
#include "RwthComponent.h"
#include "Modules/ModuleManager.h"
-class FWidgetInteractionModule : public IModuleInterface
+class WIDGETINTERACTION_API FWidgetInteractionModule : public IModuleInterface
{
public:
@@ -18,6 +18,7 @@ public:
UFUNCTION()
void OnWorldTickStart(ELevelTick, float);
+ URwthComponent* GetWidgetInteractionComponent();
private:
void CreateWidgetInteraction(USceneComponent * parent, AVirtualRealityPawn* outer);
@@ -26,4 +27,5 @@ private:
TBaseDelegate<void, ELevelTick, float> on_world_tick_start_delegate_;
URwthComponent * widget_interaction_cmp_;
+ UWorld* last_world;
};