Unreal compile error: -WaitMutex -FromMsBuild Code 5

I cannot compile my Unreal project (error: -WaitMutex -FromMsBuild Code 5). Just for reference: when I closed unreal, I couldn’t open it due to the issue again. I had to delete the C++ files that caused the issue and I also deleted the binary files.

The code that causes the issue is very simple. I have an *AItem *parent class that seems to work just fine (see below) and an inherited class *Explosive *that causes the compilation error. Can someone help me?

Explosive.h


#pragma once

#include "CoreMinimal.h"
#include "Item.h"
#include "Explosive.generated.h"

UCLASS()
class CPPROJ01_API AExplosive : public AItem
{
    GENERATED_BODY()
public:
    AExplosive();

    UFUNCTION()
    virtual void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;

    UFUNCTION()
    virtual void OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override;

};

Explosive.cpp



#include "Explosive.h"
#include "Components/PrimitiveComponent.h"

AExplosive::AExplosive()
{
}

void OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
}

void OnOverlapEnd(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex)
{
}


Item.h



UCLASS()
class CPPROJ01_API AItem : public AActor
{
    GENERATED_BODY()

public:    
    // Sets default values for this actor's properties
    AItem();

    UPROPERTY(VisibleAnywhere)
    class USphereComponent* CollisionSphere;

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    UFUNCTION()
    virtual void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

    UFUNCTION()
    virtual void OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

};

Item.cpp



#include "Item.h"
#include "Components/SphereComponent.h"
#include "Components/PrimitiveComponent.h"

// Sets default values
AItem::AItem()
{
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    CollisionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("CollisionSphere"));
    CollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &AItem::OnOverlapBegin);
    CollisionSphere->OnComponentEndOverlap.AddDynamic(this, &AItem::OnOverlapEnd);
}

// Called when the game starts or when spawned
void AItem::BeginPlay()
{
    Super::BeginPlay();
}

// Called every frame
void AItem::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
}

void AItem::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
    UE_LOG(LogTemp, Warning, TEXT("OverlapBegin"));
}

void AItem::OnOverlapEnd(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex)
{
    UE_LOG(LogTemp, Warning, TEXT("OverlapEnd"));
}


Error code 5 is just the “failed to compile” generic error.

Go into VS->Tools->Options->Project->Build and Run->Verbosity and turn it to Minimal. Then try building again, and search for “error” in the output window. Sometimes the error is obfuscated and well hidden.

In my experience, Code 5 errors have appeared often when I forget to #include a certain file, so you may want to ascertain whether that is the case.

Thanks so much, found the issue. When overriding a function, it is not possible/allowed to define UFUNCTION() in the child when it was already declared in the parent.

“OnOverlapBegin: Override of UFUNCTION in parent class (Item) cannot have a UFUNCTION() declaration above it; it will use the same parameters as the original declaration.”

2 Likes

And there was a second error: I called Super() in the constructor of the child class. I did not know that the base class default constructor gets called even though the child’s construction script does not show it.

Just so you know, code 5 will appear if the code fails to build for any reason. It’s nothing specific.