Unhandled Exception: EXCEPTION_ACCESS_VIOLATION writing address

Hi, I have been stuck in Crypt Raider near the end with a crash report that started happening when I am on lecture 108 onwards when I go down to the crypt area. I have backtracked to pre-crypt and deleted all the crypt set ups but it is still happening, even though it was all ok before I went down to the crypt level.

UE5 error code above.

My codes below:
Mover.h:

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

#pragma once

#include “CoreMinimal.h”

#include “Components/ActorComponent.h”

#include “Mover.generated.h”

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )

class CRYPTRAIDER_API UMover : public UActorComponent

{

GENERATED_BODY()

public:

// Sets default values for this component's properties

UMover();

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 SetShouldMove(bool ShouldMove);

private:

UPROPERTY(EditAnywhere)

FVector MoveOffset;

UPROPERTY(EditAnywhere)

float MoveTime = 6;

bool ShouldMove = false;

FVector OriginalLocation;

};

Mover.cpp:

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

#include “Mover.h”

#include “Math/UnrealMathUtility.h”

// Sets default values for this component’s properties

UMover::UMover()

{

// 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 UMover::BeginPlay()

{

Super::BeginPlay();

OriginalLocation = GetOwner()->GetActorLocation();

}

// Called every frame

void UMover::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)

{

Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

if (ShouldMove == true)

{

    FVector CurrentLocation = GetOwner()->GetActorLocation();

    FVector TargetLocation = OriginalLocation + MoveOffset;

    float Speed = FVector::Distance(OriginalLocation, TargetLocation) / MoveTime;

   

    FVector NewLocation = FMath::VInterpConstantTo(

        CurrentLocation,

        TargetLocation,

        DeltaTime,

        Speed

    );

    GetOwner()->SetActorLocation(NewLocation);

}

}

void UMover::SetShouldMove(bool NewShouldMove)

{

ShouldMove = NewShouldMove;

}

TriggerComponent.h:

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

#pragma once

#include “CoreMinimal.h”

#include “Components/BoxComponent.h”

#include “Mover.h”

#include “TriggerComponent.generated.h”

/**

*/

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )

class CRYPTRAIDER_API UTriggerComponent : public UBoxComponent

{

GENERATED_BODY()

public:

// Sets default values for this component's properties

UTriggerComponent();

protected:

// Called when the game starts

virtual void BeginPlay() override;

public:

// Called every frame

virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;



UFUNCTION(BlueprintCallable)

void SetMover(UMover* Mover);

private:

UPROPERTY(EditAnywhere)

FName AcceptableActorTag;

UMover* Mover;

AActor* GetAcceptableActor() const;

};

TriggerComponent.cpp:

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

#include “TriggerComponent.h”

UTriggerComponent::UTriggerComponent()

{

PrimaryComponentTick.bCanEverTick = true;

}

// Called when the game starts

void UTriggerComponent::BeginPlay()

{

Super::BeginPlay();

//

}

void UTriggerComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)

{

Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

AActor* Actor = GetAcceptableActor();

if (Actor != nullptr)

{

    UPrimitiveComponent* Component = Cast<UPrimitiveComponent>(Actor->GetRootComponent());

    if (Component != nullptr)

    {

        Component->SetSimulatePhysics(false);

    }

    Actor->AttachToComponent(this, FAttachmentTransformRules::KeepWorldTransform);

    Mover->SetShouldMove(true);

}

else

{

    Mover->SetShouldMove(false);

}

}

void UTriggerComponent::SetMover(UMover* NewMover)

{

if (NewMover == nullptr)

{

    return;

}

Mover = NewMover;

}

AActor* UTriggerComponent::GetAcceptableActor() const

{

TArray<AActor*> Actors;

GetOverlappingActors(Actors);

for (AActor* Actor : Actors)

{

    bool HasAcceptableTag = Actor->ActorHasTag(AcceptableActorTag);

    bool IsGrabbed = Actor->ActorHasTag("Grabbed");

    if (HasAcceptableTag && !IsGrabbed)

    {

        return Actor;

    }

}

return nullptr;

}

Grabber.h:

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

#pragma once

#include “CoreMinimal.h”

#include “Components/SceneComponent.h”

#include “PhysicsEngine/PhysicsHandleComponent.h”

#include “Grabber.generated.h”

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )

class CRYPTRAIDER_API UGrabber : public USceneComponent

{

GENERATED_BODY()

public:

// Sets default values for this component's properties

UGrabber();

protected:

// Called when the game starts

virtual void BeginPlay() override;

public:

// Called every frame

virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

UFUNCTION(BlueprintCallable)

void Grab();

UFUNCTION(BlueprintCallable)

void Release();

private:

UPROPERTY(EditAnywhere)

float MaxGrabDistance = 400;



UPROPERTY(EditAnywhere)

float GrabRadius = 100;

UPROPERTY(EditAnywhere)

float HoldDistance = 200;

UPhysicsHandleComponent* GetPhysicsHandle() const;

bool GetGrabberInReach(FHitResult& OutHitResult) const;

};

Grabber.cpp:

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

#include “Grabber.h”

#include “Engine/World.h”

#include “DrawDebugHelpers.h”

// Sets default values for this component’s properties

UGrabber::UGrabber()

{

// 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 UGrabber::BeginPlay()

{

Super::BeginPlay();

}

// Called every frame

void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)

{

Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

UPhysicsHandleComponent* PhysicsHandle = GetPhysicsHandle();

if (PhysicsHandle && PhysicsHandle->GetGrabbedComponent())

{

    FVector TargetLocation = GetComponentLocation() + GetForwardVector() * HoldDistance;

    PhysicsHandle->SetTargetLocationAndRotation

    (

        TargetLocation,

        GetComponentRotation()

    );

}

}

void UGrabber::Grab()

{

UPhysicsHandleComponent* PhysicsHandle = GetPhysicsHandle();

if (PhysicsHandle == nullptr)

{

    return;

}

FHitResult HitResult;

bool HasHit = GetGrabberInReach(HitResult);

if (HasHit)

{

    UPrimitiveComponent* HitComponent = HitResult.GetComponent();

    HitComponent->WakeAllRigidBodies();

    HitResult.GetActor()->Tags.Add("Grabbed");

    PhysicsHandle->GrabComponentAtLocationWithRotation

    (

        HitComponent,

        NAME_None,

        HitResult.ImpactPoint,

        GetComponentRotation()

    );

}

}

void UGrabber::Release()

{

UPhysicsHandleComponent* PhysicsHandle = GetPhysicsHandle();

if (PhysicsHandle && PhysicsHandle->GetGrabbedComponent())

{

    AActor* GrabbedActor = PhysicsHandle->GetGrabbedComponent()->GetOwner();

    GrabbedActor->Tags.Remove("Grabbed");

    PhysicsHandle->ReleaseComponent();

}

}

UPhysicsHandleComponent* UGrabber::GetPhysicsHandle() const

{

UPhysicsHandleComponent* Result = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();

if (Result == nullptr)

{

    UE_LOG(LogTemp, Error, TEXT("Grabber requires a UPhysicsHandleComponent."));

}

return Result;

}

bool UGrabber::GetGrabberInReach(FHitResult& OutHitResult) const

{

FVector Start = GetComponentLocation();

FVector End = Start + GetForwardVector() * MaxGrabDistance;

DrawDebugLine

(

    GetWorld(),

    Start,

    End,

    FColor::Red

);

DrawDebugSphere

(

    GetWorld(),

    End,

    10,

    10,

    FColor::Blue,

    false,

    5

);



FCollisionShape Sphere = FCollisionShape::MakeSphere(GrabRadius);

return GetWorld()->SweepSingleByChannel

(

    OutHitResult,

    Start,

    End,

    FQuat::Identity,

    ECC_GameTraceChannel2,

    Sphere

);

}

I have checked all the tags are correct for Unlock1, redid the blueprint for BP_SecretWall a few times for the SetMover as well and has been stuck for quite a while:
setmover

Would appreciate if there is some help.
Thanks.

The error message you posted is for Obstacle Assault which is the section prior to Crypt Raider.

Can you post the actual error you are getting from CR?

Hi Steve, apologies for the error. I have amended the post, and also pasting the error message here below:

Prethanks!

Your TriggerComponent most likely doesn’t have Mover assigned.

Also for a code block please highlight the text and select the </> button; alternatively wrap the code in 3 backticks

```
like so
```

Hi Daniel, thanks for your reply.
Unfortunately I have tried and it does not seem to be working.

  1. Tried deleting and re-adding trigger and mover to my BP_SecretWall, and redrawing out the function on blueprint:

  2. Also checked my mover.cpp function which calls for SetShouldMove, made sure SetShouldMove function is typed in mover.h (No difference in the code above)

  3. Checked TriggerComponent.h which has the UMover* Mover; variable, also checked TriggerComponent.cpp has the setting of Mover to SetShouldMove boolean

  4. Tried removing mover and trigger from BP_SecretWall, and also the blueprint code in BP_SecretWall in relation to mover and trigger, and hit play, and still crashes; also tried this then close UE then rebuild in VSC then reopen US, still crashes

I also removed everything from level blueprint, also tried to test and put in BP_SecretWall as trigger and mover in level blueprint, all crashed so far

Could you try adding guarding against Mover dereferences? e.g.

void UTriggerComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
    // Exit early if Mover is nullptr
    if (!Mover)
    {
        UE_LOG(LogTemp, Error, TEXT("Mover is nullptr on %s"), *GetOwner()->GetName())
        return;
    }

    AActor* Actor = GetAcceptableActor();
    if (Actor != nullptr)
    {
        UPrimitiveComponent* Component = Cast<UPrimitiveComponent>(Actor->GetRootComponent());
        if (Component != nullptr)
        {
            Component->SetSimulatePhysics(false);
        }
        Actor->AttachToComponent(this, FAttachmentTransformRules::KeepWorldTransform);
        Mover->SetShouldMove(true);
    }
    else
    {
        Mover->SetShouldMove(false);
    }
}
1 Like

Oh it did come up with an error log:


LogTemp: Error: Mover is nullptr on StaticMeshActor_41

I found the static mesh via the finder, which turns out to be a random piece of floor that I accidentally put the trigger component on, likely when trying to do the vault lecture. Thanks Daniel, the UE Log thing is very helpful!

1 Like

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

Privacy & Terms