Crashing on screen debug message only when inside if statement

I have this function that is run on BeginPlay():

void UInventory::InventorySafetyChecks()
{
	playerPawn = Cast<AShooterGameCharacter>(this->GetOwner());

	

	if (playerPawn)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5, FColor::White, "its all ok here");
		if (playerPawn->invItemsDB)
			itemsDB = playerPawn->invItemsDB;
		else {
			UE_LOG(InventoryLog, Error, TEXT("playerPawn->invItemsDB is NULL!  @UInventory::BeginPlay"))
		}
	}
	else
	{
		UE_LOG(InventoryLog, Error, TEXT("playerPawn is NULL!  @UInventory::BeginPlay"))
	}

	//Code executed only on owning client
	if (playerPawn->GetController())
		if (!playerPawn->GetController()->IsLocalController())
		return;
	
	GEngine->AddOnScreenDebugMessage(-1, 10, FColor::White, "runnin'");

	hud = Cast<AGameHUD>(UGameplayStatics::GetPlayerController(this, 0)->GetHUD());
	//hud = Cast<AGameHUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
}

and when this command GEngine->AddOnScreenDebugMessage(-1, 5, FColor::White, "its all ok here"); is execute I get the following error:

Fatal error: [File:D:\Build\++UE4+Release-4.14+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\GarbageCollection.cpp] [Line: 547] 
Invalid object in GC: 0x00000098a82cbcd0, ReferencingObject: Inventory /Game/ThirdPersonCPP/Maps/UEDPIE_1_ThirdPersonExampleMap.ThirdPersonExampleMap:PersistentLevel.Player_C_0.Inventory, ReferencingObjectClass: Class /Script/ShooterGame.Inventory, Property Name: equipActor, Offset: 24, TokenIndex: 15


KERNELBASE.dll
UE4Editor-Core.dll!FOutputDeviceWindowsError::Serialize() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:103]
UE4Editor-Core.dll!FOutputDevice::Logf__VA() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\misc\outputdevice.cpp:68]
UE4Editor-Core.dll!FDebug::AssertFailed() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:332]
UE4Editor-CoreUObject.dll!TFastReferenceCollector<FGCReferenceProcessor,FGCCollector,FGCArrayPool,0>::ProcessObjectArray() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\fastreferencecollector.h:281]
UE4Editor-CoreUObject.dll!TGraphTask<TFastReferenceCollector<FGCReferenceProcessor,FGCCollector,FGCArrayPool,0>::FCollectorTask>::ExecuteTask() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\async\taskgraphinterfaces.h:868]
UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasks() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:1255]
UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasksUntilQuit() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:1149]
UE4Editor-Core.dll!FTaskThreadBase::Run() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:621]
UE4Editor-Core.dll!FRunnableThreadWin::Run() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:74]
UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:31]
KERNEL32.DLL
ntdll.dll
ntdll.dll

Crash in runnable thread TaskGraphThreadNP 2

However this error only occurs if the command GEngine->AddOnScreenDebugMessage(-1, 5, FColor::White, "its all ok here"); is inside the first if statement, if I put it like this:

GEngine->AddOnScreenDebugMessage(-1, 5, FColor::White, "its all ok here");

	if (playerPawn)
	{

the engine does not crash.

Also it only crashes if i’m runnning the game multiplayer (2 players), if I’m running it singleplayer the game does not crash. It looks like that the crash is occurring on the client. Maybe I’ve done something wrong with the spawning of the UInventory component on the player (the component is replicated).

Thanks in advance!

(and sorry for my bad english :p)

I don’t know how I solved it, but I did… (I probably did something wrong when spawning it)