Hello everyone. I ran into some trouble trying to add a NiagaraSystem to my project. Basically everything appears to be working in editor but as soon as I package my build the app crashes on launch. Bear with me as I explain:
Try to spawn a NiagaraSystem when a bullet hits a wall. Runs in editor, packages build, crashes on packaged game launch. In this example I’m using a default explosion system just to simplify things –
The crash:
If I edit my code to the following, package my game, run the packaged game - success. No crash on boot. (no particle system either)
Throw the particle system in a level, (putting the system on loop so I can see it.) Compile, package, run packaged game - no crash in the packaged game, everything is fine.
I think you just can’t package a c++ game with niagara yet.
Here are some steps to reproduce:
Make a new C++ FirstPerson template project
Enable the Niagara & Niagara Extras plugin
Create a new NiagaraSystem (SimpleExplosion)
Open FirstPersonCharacter blueprint, add an EventTick, add a SpawnSystemAtLocation (use get actor location), Select SimpleExplosion from step 2…
Package game (I use project launcher – here are my settings for the project: Build Config: Development & Build UAT: true, Cook By the Book (select WindowsNoEditor), Cook Maps: FirstPersonExampleMap, Package: package & store locally, Deploy: Do Not Deploy
Open the game & See the crash…
Tested on 4.21.0 & 4.21.2
(If you use a blueprint project btw, in step 1, everything works)
In Engine/Plugins/FX/Niagara/Source/Niagara/Public/NiagaraTypes.h ~line 443 it’s this line that crashes, the CastChecked<UScriptStruct>(Struct) part. The Struct variable is null here.
Hey! Just in case anyone stumbles onto this who’s using UEngine <= 4.21; Cultrarius on the Epic Team informed me that this will be fixed in the upcoming 4.22 Release.
Currently UE4 loads the GameModeBase of a cooked project at a stage before any Plugins are loaded. If your project’s GameModeBase hard references any UClass which itself may be hard referencing a Niagara asset, the Niagara asset will attempt to load before the Niagara plugin has been loaded which results in this cryptic error. (For more about “hard” and “soft” references, please refer to the documentation on asset references here: https://docs.unrealengine.com/en-US/Programming/Assets/ReferencingAssets/index.html)
To give a common example, if your default GameMode hard references your default Actor/Pawn, and your default Actor or Pawn hard references a Niagara System, you may experience this issue.
A resolution is in the works, but for now it is possible to work around this problem in content by loading your Niagara assets through soft object paths when needed. Please refer to this answerhub post for an example. Workaround For UE-71147 - Programming & Scripting - Unreal Engine Forums
Have you found a solution to this problem? We’re encountering the same issue if our pawn owns a UNiagaraComponent that is constructed in the constructore. If we remove the ConstructorHelpers for said component everything works in the packaged build. Well… Everything except that overridden parameters are not taken into consideration and therefore our mesh reproduction isn’t working anymore. Only in the packaged build though. Everything works in the editor exactly as intended…