I have a custom weapon which on creation should call a function in the custom
game state to “register itself”, so the game state has it in a variable for quick
reference. After setting this up everything compiles fine. When starting a PIE
session, the editor crashes. From then on if anything attempts to touch any of
the assets involved, the editor crashes:
Opening a map with the custom game state referenced.
Opening the weapon class to edit.
Opening any blueprint interface used in either of them.
Other things to note:
I’m on 4.1.1 because even a working version crashes 4.2 on startup.
Everything in the project is made with Blueprints.
What matters is making the call. The class it’s called from or the data passed
seems to be irrelevant.
I have a question in AnswerHub that may be related to this, where this code no longer works in 4.2, it returns NULL for my custom GameState (worked in 4.1.1):
@Tim Hobson: There is no crash with the racer example. It seems that the 4.2 issue
is a separate one, some kind of an “assertion on asset load”. Max Preussner knows
about it already, I just mentioned it to explain why I couldn’t test it in 4.2.
@dmacesic: Interesting. I’ll set up a test to see if I can get a valid game state object
to begin with.
I’ve just checked and the GetGameState seems to return a valid object.
The PlayerArray is 1 as expected but the GetElapsedTime is always 0
regardless when I query it. I’m not sure if its a clue.
I can successfully call the GameState’s function from the player controller and the
game mode. I tried other, actor derived classes and that always ended in tears.
Just as a reference, just in case it helps you or someone else, I’ve resolved my issue. It seems the way the world pointer is managed in the player’s context is a bit different. I was using an invalid UWorld pointer to generate a Slate widget from a static function. I have used the example in Shooter Game 4.2, and used FLocalPlayerContext to get a proper pointer to the world to get the game state.
//In HUD
APlayerController* pc = GetOwningPlayerController();
FLocalPlayerContext context(pc);
// pass this to static Slate widget creation function and do
UWorld* world = Context.GetWorld();
AGameGameState* gameState = world->GetGameState<AGameGameState>();
//gameState is no longer NULL
If I move the game state function call into the pawn then I can avoid the crash. I’ll
leave it like this for now and focus on making the project work on 4.2 then re-test
everything for changes.