I have a C++ UUserWidget class, and from that I derived a blueprint class.
In the C++ class, I created a function and added the BlueprintNativeEvent Macro to it in order to be able to call the event from both c++ and blueprints and be able to add code from both.
The event is being called from both C++ and blueprints perfectly but the problem is that any code executed in the event by C++ cannot access blueprint variables. I can compile both the C++ and blueprints, but on runtime it is unable to access any blueprint-created variables and instead just gives off an error of “Accessed none”.
Am I misunderstanding how to use Blueprint Native Events or is there something else wrong?
MyWidget.h:
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/Widget.h"
#include "MyWidget.generated.h"
UCLASS()
class MYGAME_API UMyWidget : public UUserWidget
{
GENERATED_BODY()
public:
UMyWidget(const FObjectInitializer& ObjectInitializer);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Main Title")
FText MainTitleText;
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "UI")
void RefreshAll();
};
MyWidget.cpp:
#include "MyWidget.h"
UMyWidget::UMyWidget(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
RefreshAll();
}
void UMyWidget::RefreshAll_Implementation()
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Test Debug Message"));
}
BP_MyWidget (Blueprint Derived Class of MyWidget):
(Main Title is a text block created in the blueprint class).
Error On Runtime:
Blueprint Runtime Error: "Accessed None trying to read property MainTitle". Node: SetText (Text) Graph: EventGraph Function: Execute Ubergraph BP Warning Widget Blueprint: BP_WarningWidget
I’ve done some testing and this error also occurs on any blueprint-created variable used ONLY WHEN C++ CALLS THE EVENT.
I also replicated the same thing in another blueprint.
I would love some help, thanks!