Crash on SpawnActor in GameInstance - Event Init

Branch: ‘Binary’ build from the Unreal Launcher

Build version: 4.7.2

Description: This crash only occurs in standalone/cooked versions (tested windows 7 64bit), and adding a “Delay” node before the actor spawn, even with an 0.000001 delay fixes this issue.
I did not try out other ways of reproducing or fixing this but i am sure it has to do with either the executing thread that spawns the object or the order in which things like gameinstance are initialized in standalone/cooked versions.

Repro:

  1. Blank project
  2. create a and set custom game instance in project settings
  3. add “Event Init” node and spawn any actor via “SpawnActor” with any transform

Standalone and cooked versions on windows should crash with this error:

MachineId:
EpicAccountId:

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

UE4Editor_Engine!UWorld::SpawnActor() + 433 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\levelactor.cpp:232]
UE4Editor_Engine!UGameplayStatics::BeginSpawningActorFromClass() + 363 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\gameplaystatics.cpp:332]
UE4Editor_Engine!UGameplayStatics::execBeginSpawningActorFromClass() + 357 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\classes\kismet\gameplaystatics.h:31]
UE4Editor_CoreUObject!UFunction::Invoke() + 180 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:3684]
UE4Editor_CoreUObject!UObject::CallFunction() + 1112 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:395]
UE4Editor_CoreUObject!UObject::ProcessContextOpcode() + 141 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1451]
UE4Editor_CoreUObject!UObject::execLetObj() + 430 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1292]
UE4Editor_CoreUObject!UObject::ProcessInternal() + 1644 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:602]
UE4Editor_CoreUObject!UObject::CallFunction() + 2707 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:516]
UE4Editor_CoreUObject!UObject::ProcessInternal() + 1644 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:602]
UE4Editor_CoreUObject!UFunction::Invoke() + 180 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:3684]
UE4Editor_CoreUObject!UObject::ProcessEvent() + 3036 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:924]
UE4Editor_Engine!UGameEngine::Init() + 853 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\gameengine.cpp:421]
UE4Editor!FEngineLoop::Init() + 1247 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launchengineloop.cpp:1967]
UE4Editor!GuardedMain() + 933 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launch.cpp:136]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

Hi DrUniversalis,

Can you post your crash logs? These can be found at \Unreal Projects\PROJECTNAME\saved\logs.

The reason it works in editor and not in cooked builds is that the editor handles game instances a little differently. In cooked builds, GameInstances will call init before a level is loaded, and spawning an actor without a level being loaded is a bad idea. Having a delay kicks the spawning off to the next frame, which generally has a level loaded due to everything that is happening when the GameInstance among other things are initialized.

You should move your SpawnActor to the GameMode class or some other class or function that is guaranteed to be called when a level exists. One way to guarantee this in a GameInstance class is to assign a method or event in your custom GameInstance to the FCoreUObjectDelegates::PostLoadMap delegate, which gets fired after the successful load of any map.

Thanks, will look into that. In particular I am spawning a sound manager, I figured its an object that should be available in the whole game, and reloading it in every level seems wrong. Its a Blueprint only game so i am not quite sure if the delegate you mentioned is available for me (no ue at the moment).

will do as soon as i get in the office

forgot about this sorry, here is the crash log

Hi drUniversalis,

Can you show me a screenshot of your GameInstance setup? Specifically the spawn functionality. I am attempting to reproduce this on my end but thus far have not had any luck.

edited, so maybe it’s only on specific machines

Can you post your dxdiag so I can take a look? Thank you!

edited :slight_smile:

Hi drUniversalis,

Just letting you know I edited the page a bit to make it more readable. I’ve included your dxdiag and logs in two .txt files within the page. I’ll test this again today to see if I can reproduce it on my end. If I need more information I’ll post here again. Thank you for your continued patience while we attempt to reproduce this on our end!

Hi drUniversalis,

I was able to reproduce this and have entered a bug report, UE-12168 to be assessed by the development staff.

great explanation, fixed problems i was having trying to run operations off the event init on the game instance. thank you!