Game crashes when running in '-game' mode and hitting a Custom K2Node

I’ve created a Custom K2Node subclassed from K2Node_Switch. When I play the game in the editor, everything behaves as expected. However, when I launch DevelopmentEditor with the ‘-game’ tag, the game crashes when it reaches the Custom Node. The output spits out:


LogLinker: Warning: Can’t find file for asset ‘/Script/MyModuleEditor’ while loading NULL.

LoadErrors: Failed to load /Script/MyModuleEditor.K2Node_CustomSwitch Referenced by EventGraph


It seems like the issue is that my K2Node_CustomSwitch is defined in an Editor Module, which is not loaded when running with ‘-game’. I can’t manually load that module as the engine then complains about loading the MainFrameModule when running with -game and I can’t move the custom switch node to a non-editor module as it depends on K2Node_Switch, which is in an editor module.

This seems like it would be an issue with any Custom K2Node. How do I get around this issue?

There no such things as “Custom K2Node”, note that you adding module to the engine and effectively the engine and blueprint system, so your node is as custom as any other node. So most likely you doing something wrong or missing something impotent, as existing nodes don’t need BlueprintGraph module to be loaded either (K2Node_Switch isn’t there too, isn’t?).

My guess is your code depends on node instance it self and does not generate VM machine code which is used at runtime. I never attepted to make new K2Node so i dont really know what is exacly needed, but i played with graph editor and one thing i learned from is fact that nodes in any graphs in UE4 editor are like source code, they only exist in editor and it’s just used to generate final product that is used in runtime. You should cut any runtime refrences to your node, if you made any, thats the most impotent thing, and let blueprint compiler do it’s thing. Check if there anything in node that make it needed to exist in runtime. And most importently you should look on Compile function:

https://github.com/EpicGames/UnrealEngine/blob/b70f31f6645d764bcb55829228918a6e3b571e0b/Engine/Source/Editor/BlueprintGraph/Private/K2Node_Switch.cpp#L51

As this is function which suppose to generate VM runtime code from your node and make blueprint independent from your node instance.

In other words your node needs to reproduce what other nodes does.

I did some more testing, and there definitely seems to be something wrong with the engine. I took the K2Node_SwitchString class and created a duplicate of it at the engine level (within the BlueprintGraph module). That class worked fine. However, when I would move that class to any other module, I would get a crash when running in -game mode an execution reached that node. I tried the placing it in an editor module inside a plugin (one made specifically for this test with minimal dependencies) and inside of an editor module at the game level. All of these failed.

I even tried following this example from epic. (A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums) It didn’t work.

What ended up working is placing my custom K2Node inside of a module marked as “Developer”. This way, the module is loaded in both editor and -game modes. This seems to have everything behave as expected.