Crash with multiple players

When I play with more than 1 player or in a dedicated server my editor crashes. The crash happens due to a function that gets called in PostInitializeComponents(). In it I’m calling a function called ‘InitialiseWeaponInventory()’ which would spawn a weapon inventory actor, which would attach itself to the player and would than spawn a couple of weapons. When I play in a server or with multiple players, my game crashes after the 1st tick happened with this in the logs:

Any idea how I can fix this?

Screenshots of the CPP file:

Move SetOwner() inside the if-statement that makes sure the pointer is valid. And probably do an else with a log message saying the pointer was bad.

Also, when you cast the game state, make sure it’s not null before using it.

A less likely problem is that GetWorld() is returning a null pointer