How to Access WidgetInteractionComponent from C++?

I’m trying to forward events to my 3D UMG menu from my C++ player controller.

I started with


#include "Components/WidgetInteractionComponent.h"

which quickly lead to crazy amounts of undeclared header dependencies (surely I’m doing something wrong, Epic can’t be that undisciplined with their code?!)


#include "Layout/SlateRect.h"
#include "Layout/Visibility.h"
#include "Layout/ArrangedWidget.h"
#include "Layout/ArrangedChildren.h"
#include "Layout/WidgetPath.h"
#include "HAL/ThreadingBase.h"
#include "Application/SlateApplication.h"
#include "Components/WidgetInteractionComponent.h"

And this is very far from complete. My Project.Build.cs is


PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "SlateCore" });

Is there any example of using the WidgetInteractionComponent from C++?

I can only find the blueprint documentation of it and the feature is marked “Experimental” so it’ll most likely be a while before someone does something with it and posts it in C++.

Unless @Rama does it or something.

First, have you tried to add “Slate” into public PublicDependencyModuleNames?

PublicDependencyModuleNames.AddRange(new string] { “Core”, “CoreUObject”, “Engine”, “InputCore”, “UMG”, “Slate”, “SlateCore” });

Please try.

No change.

I set the dependencies as you said and even if I put the include directive for WidgetInteractionComponent.h in the .cpp file instead (so it comes after .generated.h and anything that could possibly pull in required headers), I always end up where I started my journey through the header maze last time:


[2016.09.28-21.39.19:865] 76]Warning: Starting HotReload took  2.7s.

In file included from /mnt/devel/GameDev/MyGame/Source/MyGame/Menu/MenuPlayerController.cpp:7:                                                                                        
In file included from Runtime/UMG/Public/Components/WidgetInteractionComponent.h:5:           
Runtime/UMG/Public/Components/WidgetComponent.h:112:9: error: use of undeclared identifier
      'FWidgetAndPointer'
        TArray<FWidgetAndPointer> GetHitWidgetPath(FVector WorldHitLocation, bool bIgn...
               ^


followed by two more screenfulls of unknown types + undeclared identifiers.

Hi there @cygon and @Vipar!

I had no issue getting the include to work using the following setup:

  1. Build.cs, I am using just UMG as a public dependency (no Slate or SlateCore)


PublicDependencyModuleNames.AddRange(new string] { 
	"UMG"
});


  1. Top of class that wants to use WidgetInteractionComponent:


#pragma once
 
#include "UMG.h"

#include "Blueprint/UserWidget.h"
 
//Access to new UMG interface in C++ !  <3 Rama
#include "Components/WidgetInteractionComponent.h"

#include "JoyContext.generated.h"


My conclusion:

You probably just have to put:


#include "UMG.h"

above your current setup :slight_smile:

Enjoy!

:heart:

Rama