UStaticMeshComponent ptr becomes invalid (null) the second time I hit play on editor, works well the first time

Issue: UStaticMeshComponent (Sword) becomes null / not valid the second time I hit play on the editor.

Video Showcase: https://youtu.be/N1LQXJMgVes

As you can see in the video. The first time I hit play, you are able to see the hit box of the Sword working just fine. When I stop the game and hit play again, for any reason the sword component becomes null on the C++ side but I can still see it on the viewport.

Here’s the Code where the UE Log message with the Error spans from:

void APlayerCharacter::HitDetect()
{
    
	if (!IsValid(Sword))
	{
		UE_LOG(LogTemp, Error, TEXT("Invalid Sword reference"));
		
		return;
	}

	UE_LOG(LogTemp, Error, TEXT("Breakpoint 1"));
    
	if (HitObjectTypes.Num() <= 0)
	{
		UE_LOG(LogTemp, Warning, TEXT("No hit object types defined"));
		return;
	}

	FVector HitStart = Sword->GetSocketLocation(TEXT("start"));
	FVector HitEnd = Sword->GetSocketLocation(TEXT("end"));

	FHitResult HitResult;
	TArray<AActor*> ValidActorsToIgnore;
    
	// Filter out invalid actors
	for (AActor* Actor : ActorsToIgnore)
	{
		if (IsValid(Actor))
		{
			ValidActorsToIgnore.Add(Actor);
		}
	}
    
	bool hit = UKismetSystemLibrary::SphereTraceSingleForObjects(
		GetWorld(), 
		HitStart, 
		HitEnd, 
		10, 
		HitObjectTypes, 
		false, 
		ValidActorsToIgnore,  
		EDrawDebugTrace::ForDuration, 
		HitResult, 
		true
	);
    
	if (hit)
	{
		UE_LOG(LogTemp, Warning, TEXT("Just hit a pawn"));
	}
}

For anyone wondering, if I do this:

if (Sword)

Instead of this:

if (!IsValid(Sword))

The engine crashes.

void APlayerCharacter::HitDetect()

Is Called from a Notify State script:

void UAnimNotifState_HItDetection::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation,
	float FrameDeltaTime, const FAnimNotifyEventReference& EventReference)
{
	Super::NotifyTick(MeshComp, Animation, FrameDeltaTime, EventReference);

	if (!IsValid(MeshComp) || !IsValid(MeshComp->GetOwner()))
	{
		return;
	}

	if (!PlayerCharacter)
	{
		PlayerCharacter = Cast<APlayerCharacter>(MeshComp->GetOwner());
	}
    
	if (PlayerCharacter)
	{
		UE_LOG(LogTemp, Warning, TEXT("Character is Valid for Notif State"));
		PlayerCharacter->HitDetect();
	}else
	{
		UE_LOG(LogTemp, Error, TEXT("Player Character Not Valid"));
	}
}

What I’ve tried:

  1. Deleting, Intermediate, Saved, and Binaries folder, regenerating project files, and rebuild.
  2. Removing the category from uproperty for the Sword:
UPROPERTY(EditAnywhere)
UStaticMeshComponent* Sword;

I do not know what else todo at this point, I am just stuck. It makes no sense that it works the first time I hit play and not the second, nothing changes, the sword is clearly visible on screen the second time.

Here’s my PlayerCharacter constructor if that’s worth anything:

APlayerCharacter::APlayerCharacter()
{
	PrimaryActorTick.bCanEverTick = true;

	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Camera Spring Arm"));

	SpringArm->SetupAttachment(RootComponent);

	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Player Camera"));

	Camera->SetupAttachment(SpringArm);

	Sword = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SwordCompt"));
	
	Sword->SetupAttachment(GetMesh() , TEXT("S_SwordR_v2"));
}

Try checking the sword to a null pointer

if (Sword == nullptr){
		UE_LOG(LogTemp, Error, TEXT("Invalid Sword reference"));		
		return;
}

It needs a UPROPERTY otherwise it will be garbage collected.

On the second run if you eject from the character and pause the game, when selecting the character is the sword empty in the details panel at runtime?

On the second run if you eject from the character and pause the game, when selecting the character is the sword empty in the details panel at runtime?

The Sword is still there:

Tried:

	if (Sword == nullptr)
	{
		UE_LOG(LogTemp, Error, TEXT("Invalid Sword reference"));
		
		return;
	}

It skips the if statement which means the Sword is NOT a nullptr but the Engine crashes with this error as soon as I attempt the perform the basic attack which calls the HitDetect function:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x0000000000000000

UnrealEditor_ThreeWorlds!APlayerCharacter::HitDetect() [E:\Unreal Projects\ThreeWorlds\Source\ThreeWorlds\PlayerCharacter.cpp:88]
UnrealEditor_Engine!UAnimInstance::TriggerAnimNotifies() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:1645]
UnrealEditor_Engine!UAnimInstance::DispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:781]
UnrealEditor_Engine!USkeletalMeshComponent::ConditionallyDispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:1825]
UnrealEditor_Engine!USkeletalMeshComponent::FinalizeBoneTransform() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4480]
UnrealEditor_Engine!USkeletalMeshComponent::FinalizeAnimationUpdate() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PhysicsEngine\PhysAnim.cpp:475]
UnrealEditor_Engine!USkeletalMeshComponent::PostAnimEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:2952]
UnrealEditor_Engine!USkeletalMeshComponent::CompleteParallelAnimationEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4339]
UnrealEditor_Engine!FParallelAnimationCompletionTask::DoTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:283]
UnrealEditor_Engine!TGraphTask<FParallelAnimationCompletionTask>::ExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:634]
UnrealEditor_Core!UE::Tasks::Private::FTaskBase::TryExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Tasks\TaskPrivate.h:504]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:779]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:668]
UnrealEditor_Core!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:1526]
UnrealEditor_Engine!FTickTaskSequencer::ReleaseTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:815]
UnrealEditor_Engine!FTickTaskManager::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1866]
UnrealEditor_Engine!UWorld::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:774]
UnrealEditor_Engine!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1518]
UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:2140]
UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:550]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5869]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:123]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:277]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:317]
UnrealEditor!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll
PlayerCharacter.cpp:88

What is on line 88 of PlayerCharacter.cpp?

Seems to be crashing at line 87 and 88 per the above error on PlayerCharacter:

FVector HitStart = Sword->GetSocketLocation(TEXT("start"));
FVector HitEnd = Sword->GetSocketLocation(TEXT("end"));

The sockets are there though, so it’s not like they don’t exist:

I also tried a second time and it’s definitely line 87 of the PlayerCharacter.cpp:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x000000000004b438

UnrealEditor_ThreeWorlds!APlayerCharacter::HitDetect() [E:\Unreal Projects\ThreeWorlds\Source\ThreeWorlds\PlayerCharacter.cpp:87]
UnrealEditor_Engine!UAnimInstance::TriggerAnimNotifies() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:1645]
UnrealEditor_Engine!UAnimInstance::DispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:781]
UnrealEditor_Engine!USkeletalMeshComponent::ConditionallyDispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:1825]
UnrealEditor_Engine!USkeletalMeshComponent::FinalizeBoneTransform() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4480]
UnrealEditor_Engine!USkeletalMeshComponent::FinalizeAnimationUpdate() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PhysicsEngine\PhysAnim.cpp:475]
UnrealEditor_Engine!USkeletalMeshComponent::PostAnimEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:2952]
UnrealEditor_Engine!USkeletalMeshComponent::CompleteParallelAnimationEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4339]
UnrealEditor_Engine!FParallelAnimationCompletionTask::DoTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:283]
UnrealEditor_Engine!TGraphTask<FParallelAnimationCompletionTask>::ExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:634]
UnrealEditor_Core!UE::Tasks::Private::FTaskBase::TryExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Tasks\TaskPrivate.h:504]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:779]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:668]
UnrealEditor_Core!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:1526]
UnrealEditor_Engine!FTickTaskSequencer::ReleaseTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:815]
UnrealEditor_Engine!FTickTaskManager::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1866]
UnrealEditor_Engine!UWorld::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:774]
UnrealEditor_Engine!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1518]
UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:2140]
UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:550]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5869]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:123]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:277]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:317]
UnrealEditor!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll
	FVector HitStart = Sword->GetSocketLocation(TEXT("start"));

The sockets may be there but if the sword isn’t then you will get a crash when trying to get them from a nullptr

Yes, but I guess we can rule out it’s a null pointer as it’s going pass the check:

void APlayerCharacter::HitDetect()
{
    
	if (Sword == nullptr)
	{
		UE_LOG(LogTemp, Error, TEXT("Invalid Sword reference"));
		
		return;
	}

	UE_LOG(LogTemp, Error, TEXT("Breakpoint 1"));
    
	if (HitObjectTypes.Num() <= 0)
	{
		UE_LOG(LogTemp, Warning, TEXT("No hit object types defined"));
		return;
	}

	FVector HitStart = Sword->GetSocketLocation(TEXT("start"));
	FVector HitEnd = Sword->GetSocketLocation(TEXT("end"));

Ok so I just noticed it’s a void return & returns in unreal do not make if go out of the function

so remake your function like this



void APlayerCharacter::HitDetect()
{
	if (Sword != nullptr)
	{
		// Rest of code
	}
}

If it’s a null then it will silently skip over the code.

Though sword does not fail even when the mesh is not set as it is created through the CreateDefaultSubobject command.

Are you sure you are editing the correct header file and that it has the UPROPERTY macro?

This is the entire PlayerCharacter.h file:

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

#pragma once

#include "CoreMinimal.h"
#include "BaseCharacter.h"
#include "PlayerCharacter.generated.h"

class UCameraComponent;
class USpringArmComponent;
struct FInputActionValue;
class UInputAction;
class UInputMappingContext;
/**
 * 
 */
UCLASS()
class THREEWORLDS_API APlayerCharacter : public ABaseCharacter
{
	GENERATED_BODY()
public:
	APlayerCharacter();
	
protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	UPROPERTY(EditAnywhere)
	UStaticMeshComponent* Sword;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animation")
	UAnimMontage* AttackMontage1;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animation")
	UAnimMontage* AttackMontage2;

	UFUNCTION(Blueprintable, BlueprintCallable)
	void SetIsAttacking(UAnimMontage* Montage, bool bInterrupted);
	
public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

	void HitDetect();
	
	UPROPERTY(EditAnywhere)
	TArray<TEnumAsByte<EObjectTypeQuery>> HitObjectTypes;

private:
	UPROPERTY(EditAnywhere, Category="Input")
	TSoftObjectPtr<UInputMappingContext> InputMapping;

	UPROPERTY(EditAnywhere, Category="Input")
	UInputAction* MoveForwardAction;

	UPROPERTY(EditAnywhere, Category="Input")
	UInputAction* LookUpAction;
	
	UPROPERTY(EditAnywhere, Category="Input")
	UInputAction* MoveRightAction;

	UPROPERTY(EditAnywhere, Category="Input")
	UInputAction* LookRightAction;
	
	UPROPERTY(EditAnywhere, Category="Input")
	UInputAction* JumpAction;

	UPROPERTY(EditAnywhere, Category="Input")
	UInputAction* BasicAttackAction;

	UPROPERTY(EditAnywhere, Category="Input")
	UInputAction* CameraScrollDistanceAction;

	APlayerController* PlayerController;

	UPROPERTY(EditAnywhere, Category="Player Camera")
	USpringArmComponent* SpringArm;

	UPROPERTY(EditAnywhere, Category="Player Camera")
	UCameraComponent* Camera;
	
	UPROPERTY(EditAnywhere, Category="Player Camera")
	int MinScrollDistance = 100;
	
	UPROPERTY(EditAnywhere, Category="Player Camera")
	int MaxScrollDistance = 600;
	
	
	TArray<AActor*> ActorsToIgnore = {this};
	
	void MoveForward(const FInputActionValue& Value);
	void LookUp(const FInputActionValue& Value);
	void MoveRight(const FInputActionValue& Value);
	void LookRight(const FInputActionValue& Value);
	void CameraScroll(const FInputActionValue& Value);

	void BasicAttack(const FInputActionValue& Value);
	
	
	float CameraScrollAmount = 10;

	int AttackCounter = 0;
	bool IsAttacking = false;
	
	void SetupInputMappingContext();
};

Tried:

void APlayerCharacter::HitDetect()
{
    
	if (Sword != nullptr)
	{
		if (HitObjectTypes.Num() <= 0)
		{
			UE_LOG(LogTemp, Warning, TEXT("No hit object types defined"));
			return;
		}

		FVector HitStart = Sword->GetSocketLocation(TEXT("start"));
		FVector HitEnd = Sword->GetSocketLocation(TEXT("end"));

		FHitResult HitResult;
		TArray<AActor*> ValidActorsToIgnore;
	    
		// Filter out invalid actors
		for (AActor* Actor : ActorsToIgnore)
		{
			if (IsValid(Actor))
			{
				ValidActorsToIgnore.Add(Actor);
			}
		}
	    
		bool hit = UKismetSystemLibrary::SphereTraceSingleForObjects(
			GetWorld(), 
			HitStart, 
			HitEnd, 
			10, 
			HitObjectTypes, 
			false, 
			ValidActorsToIgnore,  
			EDrawDebugTrace::ForDuration, 
			HitResult, 
			true
		);
	    
		if (hit)
		{
			UE_LOG(LogTemp, Warning, TEXT("Just hit a pawn"));
		}
	}
}

Failed with the same error as earlier on Sword->GetSocketLocation(TEXT(“start”));

Ok so I believe the problem is elsewhere. It happens when you are accessing the mesh.
The sword is probably not null but it’s static mesh so try:

void APlayerCharacter::HitDetect()
{		
	if (Sword && Sword->GetStaticMesh() == nullptr) 
	{
		UE_LOG(LogTemp, Error, TEXT("Invalid Sword reference"));
		return;
	}

	UE_LOG(LogTemp, Error, TEXT("Breakpoint 1"));
    
	if (HitObjectTypes.Num() <= 0)
	{
		UE_LOG(LogTemp, Warning, TEXT("No hit object types defined"));
		return;
	}

	FVector HitStart = Sword->GetSocketLocation(TEXT("start"));
	FVector HitEnd = Sword->GetSocketLocation(TEXT("end"));

	FHitResult HitResult;
	TArray<AActor*> ValidActorsToIgnore;
    
	// Filter out invalid actors
	for (AActor* Actor : ActorsToIgnore)
	{
		if (IsValid(Actor))
		{
			ValidActorsToIgnore.Add(Actor);
		}
	}
    
	bool hit = UKismetSystemLibrary::SphereTraceSingleForObjects(
		GetWorld(), 
		HitStart, 
		HitEnd, 
		10, 
		HitObjectTypes, 
		false, 
		ValidActorsToIgnore,  
		EDrawDebugTrace::ForDuration, 
		HitResult, 
		true
	);
    
	if (hit)
	{
		UE_LOG(LogTemp, Warning, TEXT("Just hit a pawn"));
	}
}

It should skip the code if the mesh is not set.

First time it worked, fine, second time I did get the Log error:

LogTemp: Error: Invalid Sword reference

no crash

Third time engine crashed with a different error:

Fatal error!

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000a2500000646

0x0000014358fc533a UnrealEditor-ThreeWorlds.dll!ObjectPtr_Private::IsObjectPtrEqual<UStaticMesh,UStaticMesh *,0>() [E:\Games\UE_5.5\Engine\Source\Runtime\CoreUObject\Public\UObject\ObjectPtr.h:385]
0x0000014358fc8037 UnrealEditor-ThreeWorlds.dll!APlayerCharacter::HitDetect() [E:\Unreal Projects\ThreeWorlds\Source\ThreeWorlds\PlayerCharacter.cpp:70]
0x00007fff02e37521 UnrealEditor-Engine.dll!UAnimInstance::TriggerAnimNotifies() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:1645]
0x00007fff02dd5266 UnrealEditor-Engine.dll!UAnimInstance::DispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:781]
0x00007fff03581e04 UnrealEditor-Engine.dll!USkeletalMeshComponent::ConditionallyDispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:1825]
0x00007fff0358c2bd UnrealEditor-Engine.dll!USkeletalMeshComponent::FinalizeBoneTransform() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4480]
0x00007fff0445b97b UnrealEditor-Engine.dll!USkeletalMeshComponent::FinalizeAnimationUpdate() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PhysicsEngine\PhysAnim.cpp:475]
0x00007fff035b1ddf UnrealEditor-Engine.dll!USkeletalMeshComponent::PostAnimEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:2952]
0x00007fff03580903 UnrealEditor-Engine.dll!USkeletalMeshComponent::CompleteParallelAnimationEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4339]
0x00007fff035899bc UnrealEditor-Engine.dll!FParallelAnimationCompletionTask::DoTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:283]
0x00007fff0358bf60 UnrealEditor-Engine.dll!TGraphTask<FParallelAnimationCompletionTask>::ExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:634]
0x00007fff30b62722 UnrealEditor-Core.dll!UE::Tasks::Private::FTaskBase::TryExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Tasks\TaskPrivate.h:504]
0x00007fff30b57d4a UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:779]
0x00007fff30b581ee UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:668]
0x00007fff30b659aa UnrealEditor-Core.dll!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:1526]
0x00007fff04d93c44 UnrealEditor-Engine.dll!FTickTaskSequencer::ReleaseTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:815]
0x00007fff04da36dd UnrealEditor-Engine.dll!FTickTaskManager::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1866]
0x00007fff03d6c95f UnrealEditor-Engine.dll!UWorld::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:774]
0x00007fff03d757e3 UnrealEditor-Engine.dll!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1518]
0x00007fff2dd74ce8 UnrealEditor-UnrealEd.dll!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:2140]
0x00007fff2ea03d76 UnrealEditor-UnrealEd.dll!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:550]
0x00007ff71a2e6b47 UnrealEditor.exe!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5869]
0x00007ff71a3057ac UnrealEditor.exe!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
0x00007ff71a30589a UnrealEditor.exe!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:123]
0x00007ff71a309114 UnrealEditor.exe!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:277]
0x00007ff71a31bd04 UnrealEditor.exe!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:317]
0x00007ff71a31f0ba UnrealEditor.exe!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
0x00007ff84154e8d7 KERNEL32.DLL!UnknownFunction []

line 70:

if (Sword && Sword->GetStaticMesh() == nullptr)

=========================================
Reopened project > First time, all good, works as expected.

Second time I get this error, about Hit Object Types not defined even though it’s clearly defined over there at run time:

No crash.

Third time after reopening, I was able to do a swing and then it crashed with the same error as above:

LoginId:6b0c78e8495b5e473da3bbbda75199be
EpicAccountId:72f39f207ed9493b95fa2e874b9aea77

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffffffffffff

UnrealEditor_ThreeWorlds_5566!ObjectPtr_Private::IsObjectPtrEqual<UStaticMesh,UStaticMesh *,0>() [E:\Games\UE_5.5\Engine\Source\Runtime\CoreUObject\Public\UObject\ObjectPtr.h:385]
UnrealEditor_ThreeWorlds_5566!APlayerCharacter::HitDetect() [E:\Unreal Projects\ThreeWorlds\Source\ThreeWorlds\PlayerCharacter.cpp:70]
UnrealEditor_Engine!UAnimInstance::TriggerAnimNotifies() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:1645]
UnrealEditor_Engine!UAnimInstance::DispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Animation\AnimInstance.cpp:781]
UnrealEditor_Engine!USkeletalMeshComponent::ConditionallyDispatchQueuedAnimEvents() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:1825]
UnrealEditor_Engine!USkeletalMeshComponent::FinalizeBoneTransform() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4480]
UnrealEditor_Engine!USkeletalMeshComponent::FinalizeAnimationUpdate() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PhysicsEngine\PhysAnim.cpp:475]
UnrealEditor_Engine!USkeletalMeshComponent::PostAnimEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:2952]
UnrealEditor_Engine!USkeletalMeshComponent::CompleteParallelAnimationEvaluation() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:4339]
UnrealEditor_Engine!FParallelAnimationCompletionTask::DoTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SkeletalMeshComponent.cpp:283]
UnrealEditor_Engine!TGraphTask<FParallelAnimationCompletionTask>::ExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:634]
UnrealEditor_Core!UE::Tasks::Private::FTaskBase::TryExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Tasks\TaskPrivate.h:504]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:779]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:668]
UnrealEditor_Core!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:1526]
UnrealEditor_Engine!FTickTaskSequencer::ReleaseTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:815]
UnrealEditor_Engine!FTickTaskManager::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1866]
UnrealEditor_Engine!UWorld::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:774]
UnrealEditor_Engine!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1518]
UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:2140]
UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:550]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5869]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:123]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:277]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:317]
UnrealEditor!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

Pretty random.

The Not hit Object error is coming from this check:

	if (HitObjectTypes.Num() <= 0)
	{
		UE_LOG(LogTemp, Warning, TEXT("No hit object types defined"));
		return;
	}

The array size is clearly not 0, as shown in the Screenshot above, there is 1 HitObjectType in the array of Type Pawn. Could this be an engine bug?

Try turning off optimizations in your build file (just search turn off optimizations) and stepping through the function and check if the tarray is valid with a mouse over or add watch, once you get to the check.

I would also do a project wide search if you set the weapon to null / nullptr at any point.

Do you have live coding enabled? It can screw up vs files by reverting code. Turn it off if it’s enabled.

Turned off optimizations.
Also turned off live coding about 1 hour ago to try without it as well.

Did a project wide search, no places where Sword is being set to null. I am now in debug mode, looks like the second time I hit play, there are a couple illegalities:

Next Debug Step - line 63
Sword i actually a null pointer, but not only it, but the rest of my uproperties are null, the input actions, the montages,

I feel like I Just discover fire, didn’t know the debug tool was this useful.

These are the result from the debugger, during the first play through, when it works:

Line 63, you can see on the debugger, the sword is not null which we knew from earlier:

Are these uproprty variables null during the sword swimg?

Yes, they are null during the Sword swing which is when the HitDetect is called

Going to try putting breakpoints on begin play and move right.

BeginPlay of 2nd playthru (when it crashes):

All components are defined yet and not null.

Same thing when we look right:

Performed basic attack (hitdetect), everything becomes null:

=== UPDATE 08:58 PM ======

Second Play Thru (when it crashes) with break points on Notify State, order of execution:

1.Begin Play from Character :white_check_mark::

  1. Attack, Notify Tick triggers :white_check_mark:

  2. Player Character Null because it ahs not been set yet at this point :white_check_mark:

  3. Player Character good, but all of its uproperties are null :x:

Looks like something happened right before the NotifyTick triggered that set all UPREPERTIES to null in PlayerCharacter

From the Stack:


Output:

Then:

Conclusion, it happens somewhere in between these two:
UAnimNotifState_HItDetection::NotifyTick(USkeletalMeshComponent *, UAnimSequenceBase *, float, const FAnimNotifyEventReference &) AnimNotifState_HItDetection.cpp:32

UAnimInstance::TriggerAnimNotifies(float) AnimInstance.cpp:1657

Don’t forget to check Notify State.
Also you might have a call stack in rider like in visual studio.

Check what is calling what in what order.

I’m logging off for now. Maybe you will be able to track it down now with better tools.

Oh and look into your load order for objects. Maybe a begin play of dependant actors is firing at a different time somewhere on the code.

Then things might not show up in the order you think they do. That can lead to misleading initializations and in some cases nulls.

Double check you setup the animnotify correctly

Here is a tutorial

https://jollymonsterstudio.com/2018/12/10/unreal-engine-c-fundamentals-uanimnotify-uanimnotifystate/

I did a quick setup and my character skeletal mesh comes through

In the header I override

	virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration, const FAnimNotifyEventReference& EventReference) override;
	virtual void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime, const FAnimNotifyEventReference& EventReference) override;
	virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) override;

in cpp implementation


void UAnimNotifyState_HItDetection::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration, const FAnimNotifyEventReference& EventReference)
{
	Super::NotifyBegin(MeshComp, Animation, TotalDuration, EventReference);
}

void UAnimNotifyState_HItDetection::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime, const FAnimNotifyEventReference& EventReference)
{

	Super::NotifyTick(MeshComp, Animation, FrameDeltaTime, EventReference);

	if (GEngine) 
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Notify Tick called %s"), *MeshComp->GetName()));
		

	}
}

void UAnimNotifyState_HItDetection::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference)
{

	Super::NotifyEnd(MeshComp, Animation, EventReference);

}


In game

And here is updated code I use to call the action from the notify to the character


void UAnimNotifyState_HItDetection::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime, const FAnimNotifyEventReference& EventReference)
{
	Super::NotifyTick(MeshComp, Animation, FrameDeltaTime, EventReference);
	if (Player == nullptr) 
	{
		if (APlayerCharacter* PlayerCast = Cast<APlayerCharacter>(MeshComp->GetOwner())) 
		{
			Player = PlayerCast;
		}
	} 
	if (Player != nullptr)
	{
		Player->HitDetect();
	}	 	
}

To not have to import the character, you could have it implement an interface and then call the interface in the notify. You could then use it across many characters.

Followed the tutorial, didn’t work neither.

But I got it to work by creating a blueprint derived from the C++ class:

Works flawlessly every single play-through, no crashes.

All that tells me is that the issue was specifically in the Notify state. I’ll stick with this solution, probably when I am more advance someday, it will not be an issue.