I want to program a Trigger but it gives no feedback at all and I dont know why. my code:
include “U_Castle.h”
include “GameFramework/Actor.h”
include “Components/BoxComponent.h”
// Sets default values
AU_Castle::AU_Castle()
{
// 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;
TriggerBox = CreateDefaultSubobject(TEXT(“Trigger Box”));
TriggerBox->SetupAttachment(RootComponent);
TriggerBox->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
TriggerBox->SetCollisionResponseToAllChannels(ECR_Overlap);
TriggerBox->OnComponentBeginOverlap.AddDynamic(this, &AU_Castle::Trigger);
TriggerBox->SetVisibility(true);
TriggerBox->SetHiddenInGame(false);
}
// Called when the game starts or when spawned
void AU_Castle::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AU_Castle::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AU_Castle::Trigger(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor)
{
UE_LOG(LogTemp, Warning, TEXT(“Actor %s hat den Trigger betreten!”), *OtherActor->GetName());
}
else
{
UE_LOG(LogTemp, Warning, TEXT(“Kein Actor im Trigger!”));
}
}
.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
include “CoreMinimal.h”
include “GameFramework/Actor.h”
include “Components/BoxComponent.h”
include “U_Castle.generated.h”
UCLASS()
class FOLLOWTHEKING_API AU_Castle : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
AU_Castle();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UBoxComponent* TriggerBox;
UFUNCTION()
void Trigger(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};