TriggerVolume not working?

Hi,

I’ve done everything I believe correctly. Here’s my OpenDoor.h file

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine.h"

//Must be last
#include "OpenDoor.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_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;

// This properties are private to OpenDoor only
private:
    UPROPERTY(VisibleAnywhere) // Essentially an Unreal property, if you view the OpenDoor in UE4 you'll see 
OpenAngle = 90.0 (DOESN'T AUTO COMPLETE)
	    float OpenAngle = 90.0f;

    UPROPERTY(EditAnywhere)
	    ATriggerVolume* PressurePlate;

    UPROPERTY(EditAnywhere)
	    AActor* ActorThatOpens; // Pawn inherits from Actor so you can use APawn
};

And here is my OpenDoor.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "OpenDoor.h"

#include "Gameframework/Actor.h"


// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these 
features
    // off to improve performance if you don't need them.
    PrimaryComponentTick.bCanEverTick = true;


}


// Called when the game starts
void UOpenDoor::BeginPlay()
{
    Super::BeginPlay();

    OpenDoor();

}

void UOpenDoor::OpenDoor()
{
    AActor* Owner = GetOwner(); // It is actually AActor* but you can use auto if you don't know
    FRotator NewRotation = FRotator(0.0f, -80.0f, 0.0f); // f means float
    Owner->SetActorRotation(NewRotation);
}


// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* 
ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    if (PressurePlate->IsOverlappingActor(ActorThatOpens)) {
	    OpenDoor();
    }
}

But it’s not triggering the door. Any ideas?

You are calling OpenDoor() inside BeginPlay(), so the door probably already starts the game opened.

1 Like

// Fill out your copyright notice in the Description page of Project Settings.

#include “GameFramework/Actor.h”
#include “OpenDoor.h”

// Sets default values for this component’s properties
UOpenDoor::UOpenDoor()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don’t need them.
PrimaryComponentTick.bCanEverTick = true;

// ...

}

// Called when the game starts
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();

// ...

}

void UOpenDoor::OpenDoor()
{
AActor* Owner = GetOwner();
FRotator NewRotation = FRotator(0.0f, -70.0f, 0.0f);
Owner->SetActorRotation(NewRotation);
}

// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

if (PressurePlate->IsOverlappingActor(ActorThatOp))
{
	OpenDoor();
}
	// poll the trigger	 volume every frame
// if the actorthatopens is in volume

}

still showing errors:
Build started: Project: Escape, Configuration: Development_Editor x64 ------
1>Building EscapeEditor…
1>Using Visual Studio 2019 14.26.28806 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
1>Building 4 actions with 8 processes…
1> [1/4] OpenDoor.cpp
1>C:\Users\GL63\Documents\Unreal Projects\Escape\Source\Escape\OpenDoor.cpp(28): error C2039: ‘OpenDoor’: is not a member of ‘UOpenDoor’
1> C:\Users\GL63\Documents\Unreal Projects\Escape\Source\Escape\OpenDoor.h(11): note: see declaration of ‘UOpenDoor’
1>C:\Users\GL63\Documents\Unreal Projects\Escape\Source\Escape\OpenDoor.cpp(30): error C3861: ‘GetOwner’: identifier not found
1>C:\Users\GL63\Documents\Unreal Projects\Escape\Source\Escape\OpenDoor.cpp(40): error C2065: ‘ActorThatOp’: undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(46,5): error MSB3073: The command “chcp 65001 >NUL && “C:\Program Files\Epic Games\UE_4.25\Engine\Build\BatchFiles\Build.bat” EscapeEditor Win64 Development -Project=“C:\Users\GL63\Documents\Unreal Projects\Escape\Escape.uproject” -WaitMutex -FromMsBuild” exited with code 6.
1>Done building project “Escape.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Privacy & Terms