I am very new to the UMG system. I come from Unity so it’s been a big learning overhaul for me. I have asked this question before but I don’t think I made myself clear, so let me ask it again (yes I deleted the old post) :
I started a blank c++ project. I created a new c++ class called MyActor. MyActor has two floats : currentValue and maxValue. Both are equal to 100 right now. There is a method called deplete which will deplete the currentValue overtime. This is called in the Tick function. Here is the header file :
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS(Blueprintable)
class LEARNINGWIDGETS_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Variables")
float currentValue = 100;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Variables")
float maxValue = 100;
void Deplete(float decrementValue);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
And the CPP file
#include "MyActor.h"
// Sets default values
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
void AMyActor::Deplete(float decrementValue)
{
if (currentValue != 0)
{
currentValue -= decrementValue;
}
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
Deplete(DeltaTime * 0.025);
}
I have dragged this actor into the scene now.
I want a visual representation of the current health value. So, I created a new Widget Blueprint called MyWidget_BP
I have a progress bar already set. In the progress panel, I set a bind for that progress bar. Here’s what the graph looks like:
Look at the variable called “ReferenceToMyActor”. Pretty self explanatory on what it is. Of course, I can’t set the default value since this is a WidgetBlueprint is a class default.
So now here’s my question: How do I display this widget from MyActor? I see alot of documentation doing it somewhere else, like the game mode base. I just want to show it in MyActor.
Also, how do I set ReferenceToMyActor from MyActor? Or is that possible? Instead, I see a lot of people getting their player controller and then accessing values through there. But I want to access MyActor in the scene. How would I do that? I need to access it because as you can see, I can pull out Current Value and Max Value to update the progress bar.
This has been something that seems simple but has driven me crazy. Let me know if i need to explain further, I want to know how to do this ASAP!
And F.Y.I. yes, get all actors works but it something I want to avoid. What if there are multiple actors who derive from this and use this widget blueprint, but some of their implementation is different? Get All actors of class might return me the actor I didn’t want.
I want to avoid Get all actors by tag as well. All in all, I want to be able to set that reference variable so I can reuse this Widget_BP