could somebody please help me with this, I created two Delegated and exposed them to blueprints (basically what Ben does) but the event does not get called inside the blueprints
Here is my code:
THE .h file:
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnOpenDoorRequest);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnCloseDoorRequest);
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
GENERATED_BODY()
public:
UOpenDoor();
protected:
virtual void BeginPlay() override;
public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
private:
UPROPERTY()
AActor* owner;
UPROPERTY(EditAnywhere)
ATriggerVolume* pressurePlate = nullptr;
UPROPERTY(EditAnywhere)
float requiredMass;
UFUNCTION()
float GetTotalMassOnPlate();
UFUNCTION()
void OpenDoor();
UFUNCTION()
void CloseDoor();
public:
UPROPERTY(BlueprintAssignable)
FOnOpenDoorRequest onOpenRequest;
UPROPERTY(BlueprintAssignable)
FOnCloseDoorRequest onCloseRequest;
};
THE .cpp file:
UOpenDoor::UOpenDoor()
{
PrimaryComponentTick.bCanEverTick = true;
owner = GetOwner();
requiredMass = 50;
}
float UOpenDoor::GetTotalMassOnPlate() {
float totalMass = 0;
if (pressurePlate != nullptr) {
TArray<AActor*> overlapingActors;
pressurePlate->GetOverlappingActors(overlapingActors);
for (auto* currentActor : overlapingActors) {
totalMass += currentActor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
}
}
return totalMass;
}
void UOpenDoor::OpenDoor() {
onOpenRequest.Broadcast();
return;
}
void UOpenDoor::CloseDoor() {
onCloseRequest.Broadcast();
return;
}
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
}
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (GetTotalMassOnPlate() > requiredMass) {
OpenDoor();
}
else {
CloseDoor();
}
}
Anybody who faced a similar issue and solved it or who knows what is going wrong, please help me understand where I made a mistake. Until then, I will stick with lerping the door inside c++ for its animation.
Thank you.