Trigger Volume won't report name of actors present nor will the door open

I’ve tried some of the other suggestions already written here and none of them have worked. What am I missing?

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

#include "OpenDoor.h"
#include "GameFramework/Actor.h"
#include "Runtime/Engine/Classes/Engine/World.h"

#define OUT

// 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();

	Owner = GetOwner(); //Finds owning actor
}

void UOpenDoor::OpenDoor()
{
	Owner->SetActorRotation(FRotator(0.f, OpenAngle, 0.f));
}

void UOpenDoor::CloseDoor()
{
	Owner->SetActorRotation(FRotator(0.f, CloseAngle, 0.f));	
}


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

	//Poll the trigger volume every frame.
	if (GetTotalMassOfActorsOnPlate() > 30.f) // TODO: Change into editor parameter.
	{
		//If the ActorThatOpens is in the volume then
		OpenDoor();
		LastDoorOpenTime = GetWorld()->GetTimeSeconds();
	}
	if (DoorCloseDelay <= GetWorld()->GetTimeSeconds() - LastDoorOpenTime)
	{
		CloseDoor();
	}
}

float UOpenDoor::GetTotalMassOfActorsOnPlate()
{
	float TotalMass = 0.f;

	//Find all the overlapping actors
	TArray<AActor*> OverlappingActors;
	//Iterates through them adding their masses
	for (const auto* Actor : OverlappingActors)
	{
		TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
		UE_LOG(LogTemp, Warning, TEXT("%s is on the plate."), *Actor->GetName())
	}
	PressurePlate->GetOverlappingActors(OUT OverlappingActors);
	
	return TotalMass;
}

Everyday I question my intelligence. Of course the plate isn’t going to do anything when GetOverlappingActors is called after the for loop. Changing the code from this…

float UOpenDoor::GetTotalMassOfActorsOnPlate()
{
float TotalMass = 0.f;

//Find all the overlapping actors
TArray<AActor*> OverlappingActors;
//Iterates through them adding their masses
for (const auto* Actor : OverlappingActors)
{
	TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
	UE_LOG(LogTemp, Warning, TEXT("%s is on the plate."), *Actor->GetName())
}
PressurePlate->GetOverlappingActors(OUT OverlappingActors);

return TotalMass;
}

to this…

float UOpenDoor::GetTotalMassOfActorsOnPlate()
{
float TotalMass = 0.f;

//Find all the overlapping actors
TArray<AActor*> OverlappingActors;
PressurePlate->GetOverlappingActors(OUT OverlappingActors);
//Iterates through them adding their masses
for (const auto* Actor : OverlappingActors)
{
	TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
	UE_LOG(LogTemp, Warning, TEXT("%s is on the plate."), *Actor->GetName())
}

return TotalMass;
}

fixes it.

Nice!
Anyway, as I remember to any member, please share more detail and ALWAYS UE version and VS version!

Privacy & Terms