Hi everyone, im kinda new to Unreal and I am following a course online that at the moment isnt helpfull.
I create a room with a Trigger Volume and a Door. The goal should be to open the door when u enter to the trigger volume. I tried to check the code line by line (2H) and it is perfect. Now Im trying to understand better how function TickCOmponent works because seems that it doesnt trigger at all when I play the game. I tried to put a UE_LOG inside the TickComponent function and nothing print, I thought maybe developer remove the possibility to use EU_LOG in a function called every frame, make sense, so ok. Then I tried to activate these two variable
PrimaryComponentTick.bCanEverTick = true;
PrimaryComponentTick.bStartWithTickEnabled = true;
But nothing change
Then also tried to insert SetComponentEnabled(true) at the beginning of BeginPlay() but nothing, no way to make it open. I leave my code belove, really hope that someone can help me cause im struggling with this silly stuff for 4-5H.
CPP file
#include "OpenDoor.h"
#include "Engine/World.h"
#include "Components/ActorComponent.h"
// Called when the game starts
// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
{
PrimaryComponentTick.bCanEverTick = true;
}
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
Owner = GetOwner();
ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}
void UOpenDoor::OpenDoor()
{
Owner->SetActorRotation(FRotator(0.f, 0.f, 0.f));
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// Poll the trigger volume
// If the ActorThatOpens is in the volume
if (PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenDoor();
}
}
HEADER file
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine/TriggerVolume.h"
#include "OpenDoor.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class ESCAPEROOM_API UOpenDoor : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UOpenDoor();
protected:
// Called when the game starts
virtual void BeginPlay() override;
void OpenDoor();
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
private:
UPROPERTY(EditAnywhere)
float OpenAngle = 0.0f;
UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;
AActor* ActorThatOpens; // Remember pawn inherits from actor
AActor* Owner; // The owning door
};
Thank you to everyone!
An image of the Room with TriggerVolume and the Door
(NB I tried to open the Door in the BeginPlay and it opens super fine)