Building Escape - Access Violation Error?

Hi!

I’m trying to build my personal escape map and I’m getting this very annoying error that I cannot get to the bottom of. I’ve seen a question like this one before but for the original course.

I’m using UE4.24 and the lastest version of VSCode.

So, the actual problem: when I step on the one and only pressure plate on my map, everything blocks and quits and I get the error message below. This doesn’t happen with the demo map from following the tutorial, only on my own map, hence why I didn’t want to add the code and make this post too long.

This is the error message:

LoginId:9fb32e34418e80e0700ff6b016eb1ed2
EpicAccountId:47cfec11fda748499803dac46d6bcbb8

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000

UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Core
UE4Editor_Core
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

Looks like you have accessed a nullptr. Have you set the pressure plate? Also no problem with the post being long, can you also share your code?

Did the solutions in that question help? The old BuildingEscape course is quite same, the only difference between the two is that map which is given as a challenge at the end of the section.

The pressure plate I did set for the door that I’m attempting to open:

in OpenDoor.h I have:

#pragma once

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

//leave last:
#include "OpenDoor.generated.h"


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

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	void OpenDoor(float DeltaTime);
	void CloseDoor(float DeltaTime);
	float TotalActorMass() const;
	void FindAudioComponent();
	void FindPressurePlate();

private:
	float ClosedYaw;
	float CurrentYaw;

	bool DoorLockPlayedOpen;
	bool DoorLockPlayedClose;


	UPROPERTY(EditAnywhere)
	float OpenYaw = 90.f;

	float DoorLastOpened = 0.f;

	UPROPERTY(EditAnywhere)
	float DoorCloseDelay = 0.5f;

	UPROPERTY(EditAnywhere)
	float InterpSpeedOpen = 2.f;

	UPROPERTY(EditAnywhere)
	float InterpSpeedClose = 10.f;

	UPROPERTY(EditAnywhere)
	ATriggerVolume* PressurePlate = nullptr;

	UPROPERTY(EditAnywhere)
	float TargetOpenMass = 60.f;

	UPROPERTY()
	UAudioComponent* DoorLock = nullptr;
};

And in OpenDoor.cpp:

#include "OpenDoor.h"

#include "Components/AudioComponent.h"
#include "Components/PrimitiveComponent.h"
#include "Engine/World.h"
#include "GameFramework/Actor.h" 
#include "GameFramework/PlayerController.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();

	ClosedYaw = GetOwner()->GetActorRotation().Yaw;
	OpenYaw += ClosedYaw;
	CurrentYaw = ClosedYaw;

	FindPressurePlate();
	FindAudioComponent();

	DoorLockPlayedOpen = false;
	DoorLockPlayedClose = false;
}

void UOpenDoor::FindPressurePlate(){
	if(!PressurePlate)
		UE_LOG(LogTemp, Error, TEXT("%s has no PressurePlate."), *GetOwner()->GetName());
}

void UOpenDoor::FindAudioComponent(){
	DoorLock = GetOwner()->FindComponentByClass<UAudioComponent>();

	if(!DoorLock){
		UE_LOG(LogTemp, Error, TEXT("%s missing audio component DoorLock."), *GetOwner()->GetName());
	}
}

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

	if(TotalActorMass() >= TargetOpenMass){
		OpenDoor(DeltaTime);
		DoorLastOpened = GetWorld()->GetTimeSeconds();
	}
	else{
		if(GetWorld()->GetTimeSeconds() > DoorLastOpened + DoorCloseDelay){
			CloseDoor(DeltaTime);
		}
	}
}

void UOpenDoor::OpenDoor(float DeltaTime){
	FRotator OpenDoor = GetOwner()->GetActorRotation();
	
	CurrentYaw = FMath::FInterpTo(CurrentYaw, OpenYaw, DeltaTime, InterpSpeedOpen);
	OpenDoor.Yaw = CurrentYaw;

	GetOwner()->SetActorRotation(OpenDoor);

	if (!DoorLockPlayedOpen){
		DoorLock->Play();
		DoorLockPlayedOpen = true;
		DoorLockPlayedClose = false;
	}
}

void UOpenDoor::CloseDoor(float DeltaTime){
	FRotator CloseDoor = GetOwner()->GetActorRotation();
	
	CurrentYaw = FMath::FInterpTo(CurrentYaw, ClosedYaw, DeltaTime, InterpSpeedClose);
	CloseDoor.Yaw = CurrentYaw;

	GetOwner()->SetActorRotation(CloseDoor);

	if (!DoorLockPlayedClose && !DoorLockPlayedOpen){
		return;
	}
	else if (!DoorLockPlayedClose){
		DoorLock->Play();
		DoorLockPlayedClose = true;
		DoorLockPlayedOpen = false;
	}
}


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

	//Find all overlapping actors
	TArray<AActor*> OverlappingActors;
	if(PressurePlate){
		PressurePlate->GetOverlappingActors(OverlappingActors);

		//Add up the masses
		for (AActor* Actor: OverlappingActors){
			//UE_LOG(LogTemp, Warning, TEXT("%s on the pressure plate."), *Actor->GetName())
			TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
		}
	}

	return TotalMass;
}

And this is the output in the log

Found the problem!

As 70% of nullptr issues, it came from a very unexpected place… I was missing the audio component, so when the door would open or close, it’d look for an audio component that was never assigned.

My bad :smiley:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms