Hey guys, I’ll explain the whole situation. I have an ACharacter class and I factored it in an AActorComponent and called it CharacterComponent. They’re all looking good and I do a bunch of private/protected things in CharacterComponent. Now I want to acess a protected UStruct inside my character component using UI Buttons. I created a class inherited from CharacterComponent(so this way I can access the protected variable), called CharacterComponentUI, but it doesn’t work at all:
CharacterComponentUI.h file:
UCLASS()
class MEHILOONLINE_API UCharacterComponentUI : public UCharacterComponent
{
GENERATED_BODY()
public:
bool Initialize();
private:
UPROPERTY(meta = (BindWidget))
class UButton* STRButton;
UFUNCTION(BlueprintCallable)
void STRPressed();
};
CharacterComponentUI.cpp:
bool UCharacterComponentUI::Initialize()
{
bool Success = Super::Initialize();
if (!Success) return false;
if (!ensure(STRButton != nullptr)) return false;
STRButton->OnClicked.AddDynamic(this, &UCharacterComponentUI::STRPressed);
return true;
}
void UCharacterComponentUI::STRPressed()
{
UE_LOG(LogTemp, Warning, TEXT("PRESSED STR"));
}
I just did what i’m used to do with UI stuff, but unlike a UUserWidget, the class “AActorComponent” doesn’t have a Initialize().
What’s the correct approach to solve my problem?