How do I get a UI element hovering over a unit (implemented as a Character) moving on the world map, if the main class is written in C++? I think that the UI interface element will be a widget, and will need to be written as a blueprint, requiring:
The mover itself.
A C++ widget class which will act as a wrapper for the hovering stats, using the following syntax:
UPROPERTY(BlueprintReadOnly, meta=(BindWidget))
class UUserWidget* MoverStatsBPWidget;
A blueprint widget showing the hovering stats themselves, named exactly the same as the pointer above – here MoverStatsBPWidget.
Is this accurate? (Update, I’m pretty sure it isn’t. I get an unresolved external when I try to create a UUserWidget* this way.)
Also, do I need class #2, or can the MoverStatsBPWidget pointer be in the main Mover class?
Hey @PorotisDev. I believe you are getting the error because you haven’t added the “UMG” Module to your Build.cs file. Inside your project’s Source directory you should see a file that is called [YourProjectName].Build.cs that will look something like this:
public class TestProject : ModuleRules
{
public TestProject(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
}
}
You just need to add “UMG” to the PublicDependencyModuleNames array and that should fix your error.
Also, this video might help you set up your widget Show Health (Progress Bar) Above Widget | Floating Widget - Unreal Engine 4 Tutorial - YouTube. In this case, the author of the video uses the WidgetComponent and adds it to the character that he wants to have the floating widget. If you want to write your code in c++ you can create a class that inherits from this component or you can add the c++ code into the Character’s class that you want to create the widget and handle it from there. I’m not sure what you want to do exactly in C++, I hope this helps you. If this wasn’t what you were looking for please expand a little on your question.
In C++, adding UMG to PublicDependencyModuleNames is now letting things compile, and I think I connected the MoverStatsBPWidget to my MoverHoveringStats component correctly…
But I can’t figure out how to add MoverHoveringStats to MoverOnMap.
MoverOnMap.h has the following as a protected member:
But SetupAttachment isn’t there as a method, and I have no idea whether or not it’s needed. (It was required in the “rotating cube in C++” tutorial, but there was no explanation there about why it was.) I also don’t know if any other code needs to come next. What do I need to have the class MoverHoveringStats as a functioning child of MoverOnMap?
And thank you for the video! Watching it and
reading further in the documentation, I think that my MoverHoveringStats class should be a Widget in a MoverOnMap blueprint(ed actor), combining the C++ MoverOnMap and a Widget. Is that the usual architecture?
(Even if so, I’ll want to know how to connect a component to an actor for the future!)