Build succeeds, but "Play" crashes the game?


I have been tackling this issue, as I am trying to spawn a “grass” in the origin of the map, the build succeeds, the engine launches, but hitting “play” crashes the engine instantly, so I figured the error is somewhere in the constructor, or in the class spawned by the constructor. here is how I have done it:


#include “GameFramework/Actor.h”
#include “Grass.generated.h”

class THISISMYWORLD_API AGrass : public AActor

TSubobjectPtr<UStaticMeshComponent> GrassyControl;
UStaticMesh * AssetSM_GrassControl;

FORCEINLINE void SetupSMComponentsWithCollision(UStaticMeshComponent* Comp)
	if (!Comp) return;

	Comp->bOwnerNoSee = false;
	Comp->bCastDynamicShadow = true;
	Comp->CastShadow = true;
	Comp->BodyInstance.SetResponseToChannel(ECC_WorldStatic, ECR_Block);
	Comp->BodyInstance.SetResponseToChannel(ECC_WorldDynamic, ECR_Block);
	Comp->BodyInstance.SetResponseToChannel(ECC_Pawn, ECR_Block);



#include “thisIsMyWorld.h”
#include “Grass.h”

AGrass::AGrass(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshOb_AW2(TEXT(“StaticMesh’/Game/Blocks/grass.grass’”));

AssetSM_GrassControl = StaticMeshOb_AW2.Object;

GrassyControl = PCIP.CreateDefaultSubobject &lt; UStaticMeshComponent &gt;(this, TEXT("GrassyGrassControl"));

//Set Mesh

//Setup (see .h)

//Deferred Attachment
GrassyControl-&gt;AttachParent = RootComponent;
GrassyControl-&gt;AttachSocketName = FName(TEXT("GrassControl"));


Class that spawns the grass (the gamemode, as that seemed like a good universal place to put it in, as it in future will be part of procedural terrain generation)


#pragma once

#include “GameFramework/GameMode.h”
#include “Devmode.generated.h”

class THISISMYWORLD_API ADevmode : public AGameMode
UPROPERTY()FVector originPoint;
UPROPERTY()FRotator noRot;


#include “thisIsMyWorld.h”
#include “Devmode.h”
#include “PlayerChar.h”
#include “Grass.h”

ADevmode::ADevmode(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
//Beginning declarations
DefaultPawnClass = APlayerChar::StaticClass();
originPoint = FVector(0.0f, 0.0f, 0.0f);
noRot = FRotator(0.0f, 0.0f, 0.0f);
//Terrain generation
AGrass* SpawnedGrass1 = (AGrass*) GetWorld()->SpawnActor(AGrass::StaticClass(), &originPoint, &noRot);


Did you checked the log? It should say what happened.

I checked it, now the engine crashes during the loading screen, giving out: "Unhandled exception at 0x000007FED73A3F66 (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000158."When launching from launcher, the callstack is is:

Access violation - code c0000005 (first/second chance not available)

Fatal error!

UE4Editor_Engine + 4931430 bytes
UE4Editor_[projectname]!ADevmode::ADevmode() + 215 bytes [c:\users[username]\documents\unreal projects[projectname]\source[projectname]\devmode.cpp:17]
UE4Editor_CoreUObject + 334562 bytes
UE4Editor_CoreUObject + 1581260 bytes
UE4Editor_CoreUObject + 1534338 bytes
UE4Editor_CoreUObject + 731562 bytes
UE4Editor_Core + 834991 bytes
UE4Editor_Core + 1773851 bytes
UE4Editor_Projects + 82179 bytes
UE4Editor_Projects + 82717 bytes
UE4Editor!FEngineLoop::LoadStartupModules() + 74 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.3\engine\source\runtime\launch\private\launchengineloop.cpp:1765]
UE4Editor!FEngineLoop::PreInit() + 11456 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.3\engine\source\runtime\launch\private\launchengineloop.cpp:1322]
UE4Editor!GuardedMain() + 236 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.3\engine\source\runtime\launch\private\launch.cpp:112]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.3\engine\source\runtime\launch\private\windows\launchwindows.cpp:125]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.3\engine\source\runtime\launch\private\windows\launchwindows.cpp:207]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

Sounds like you have a null pointer somewhere. Use your debugger to figure out where it crashes exactly.

I’ll look into that :slight_smile:

EDIT: It’s giving me the variables originPoint and noRot, under that giving me an error “variable optimized away and not available”. How do I fix this?

This is probably not an error. The compiler optimizes originPoint and noRot so they become constant values (you never change them anywhere anyway). If you still think something is wrong at that point with those two variables, you can declare them volatile. See here:

yea, thats what I read when trying to research the subject. I guess it optimizes them to become “&FVector(0,0,0), &FRotator(0,0,0)” which causes a build error.

EDIT: adding “volatile” in the middle of the FVector&UPROPERT() caused problems, so now I have:
volatile UPROPERTY() FVector originPoint;
volatile UPROPERTY() FRotator noRot;

which gives error “class ‘FVector’: no copy contructor available or copy contructior is declared ‘explicit’”. What do I do?