Help with what's causing the engine to crash

Here’s what the crash log says:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000000

UnrealEditor_Project_2703!BlueprintFunctionScriptThing::function() [C:\Users\Admin\Documents\Unreal Projects\Project5.0\Source\Project\Private\BlueprintFunctionScriptThing.cpp:42]
UnrealEditor_Project_2703!BlueprintFunctionScriptThing::exefunction() [C:\Users\Admin\Documents\Unreal Projects\Project5.0\Intermediate\Build\Win64\UnrealEditor\Inc\Project\UHT\BlueprintFunctionScriptThing.gen.cpp:135]
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_CoreUObject
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll

I narrowed it down to the player pawn, but not sure why it has to do with it crashing

This post may help:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000000 - Development / Programming & Scripting - Epic Developer Community Forums

The problem is a null pointer: you are trying to access a memory pointer that has not been initialized yet, so it is nullptr.

Let’s take a look at this file.
BlueprintFunctionScriptThing.cpp:42

1 Like

image

{
				UNiagaraComponent* particlesystem = UNiagaraFunctionLibrary::SpawnSystemAttached(DebrisSystem, impactobject, NAME_None,FVector::ZeroVector, FRotator::ZeroRotator, EAttachLocation::KeepRelativeOffset, true, true, ENCPoolMethod::None, true);
				particlesystem->AttachToComponent(impactobject, FAttachmentTransformRules::SnapToTargetIncludingScale, NAME_None);
				if (IsValid(impactobject->GetOwner()))
				{

To prevent the crash, verify DebrisSystem and impactobject are valid before the spawnsystemattached is called… something along the lines of:
if(!DebrisSystem || !impactobject)
{return;}

Then verify you have a valid particlesystem after you create it, in case it fails to create the system. Add some logging in there to output what you’re missing.

like this?

							if (IsValid(DebrisSystem)||IsValid(impactobject))
					{
						UNiagaraComponent* particlesystem = UNiagaraFunctionLibrary::SpawnSystemAttached(DebrisSystem, impactobject, NAME_None,FVector::ZeroVector, FRotator::ZeroRotator, EAttachLocation::KeepRelativeOffset, true, true, ENCPoolMethod::None, true);
						if (IsValid(DebrisSystem) || IsValid(impactobject))
						{
							if (IsValid(DebrisSystem) || IsValid(impactobject))
							{
								particlesystem->AttachToComponent(impactobject, FAttachmentTransformRules::SnapToTargetIncludingScale, NAME_None);
								
							}
							else UE_LOG(LogTemp, Log, TEXT("CrashIndicator"));
							if (IsValid(impactobject->GetOwner()))
							{
								particlesystem->SetNiagaraVariableActor("BuildingModule", impactobject->GetOwner());
							}
							particlesystem->SetNiagaraVariableFloat("Scale", 1);
							UNiagaraDataInterfaceArrayFunctionLibrary::SetNiagaraArrayInt32(
								particlesystem,
								FName("MeshIndexes"),
								meshindexes

							);
							TArray<int32> rendereditems = UNiagaraDataInterfaceArrayFunctionLibrary::GetNiagaraArrayInt32(
								particlesystem,
								"MeshIndexes"

							);

							particlesystem->SetVisibleFlag(true);
							for (int i = 0; i < rendereditems.Num() - 1;i++)
							{
								//UE_LOG(LogTemp, Log, TEXT("Index: %i"), rendereditems[i]);
							}
							impactobject->SetVisibility(false);

						}
						else UE_LOG(LogTemp, Log, TEXT("CrashIndicator"));
						

You only need to validate them once before they are used to make sure they are pointing to an invalid object before using them. If the object is invalid, it will crash as you’ve seen, you want to catch these situations and handle them.

generally its easier and cleaner to validate inputs at the beginning of the function. If they aren’t valid, early out by 'return’ing. add a log entry in the block with the return so you know why it didn’t complete the function.

then after you create and populate the particlesystem pointer, do a:

if(!particlesystem)
{
  UE_LOG(LogTemp, Log, Text("Error creating particle system, invalid"));
  return;
}

I’ll try that tomorrow and see if it worked

fixed, I tried with that code and without it and the one without it crashed and the other one didn’t, thank you

1 Like