Hi, I’m trying to learn how to do things in c++. I have a blueprint that holds a static mesh of a minable rock. For now I just want to create a simple message when the rock is clicked so I know I can get it working.
So I added a c++ actor component to this blueprint and I’m trying to use delegates to know when it has been clicked. This is what I have so far, I’m not sure where to go from here. If it makes a difference I’m using the top down player controller starting project
header:
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "ClickableMiningRockComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FClickedDelegate);
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class GAME_API UClickableMiningRockComponent : public UActorComponent
{
GENERATED_BODY()
public:
UClickableMiningRockComponent();
UFUNCTION(BlueprintCallable, Category = "Clickable")
void OnClicked();
UPROPERTY(BlueprintAssignable, Category = "Clickable")
FClickedDelegate OnClick;
};
cpp file
#include "ClickableObject/MiningRocks/ClickableMiningRockComponent.h"
// Sets default values for this component's properties
UClickableMiningRockComponent::UClickableMiningRockComponent()
{
OnClick.AddDynamic(this, &UClickableMiningRockComponent::OnClicked);
}
void UClickableMiningRockComponent::OnClicked()
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("Actor has been clicked"));
OnClick.Broadcast();
}
