Hi, I am making a multiplayer game and have blueprints in event end play on the first person character to let the server know you have disconnected and save your data, etc… The player state returns none when it is accessed after event end play. Does anyone know a potential fix for this?
Edit: On destroy does not work either.
Could you post a screenshot of what you have?
This is on my first person character blueprint. After that it saves the data the player has in the player state and some other data.
(Either of the events allow me to retrieve the player state)
Could you post the rest of the code as well? I need to access to the reference that’s return none, as well as the context.
Sure, this is what I want to run when a player disconnects. It is not optimized and I am planning to redo it, but use of the player state will be required so this is still an issue. The only relevant screenshot is the first one and the last one I think, because that is where I get the player state.
The error occurs at the start when I try to get the player state, the error is as follows (From a packaged dedicated server when a player disconnects):
Edit: Grammar, typos.
This event is on the first person character event graph and I think that making the cast into impure will not fix the issue as the player state does not exist when this event is called. Would moving the event to the player state help to resolve the issue?
That would be a good idea. It would appear that the character is deleted after the PlayerState.
If possible, it would be best for whatever is destroying the PlayerState to call a save function on it before attempting to destroy it, that way you can ensure all relevant data is still available when you do.
However, if you can guarantee that the PlayerState is getting deleted first, you should be fine.
Changing the code over to the player state worked, thank you for the help.
This cast is failing:
Try using the success pin with a branch to check if it’s valid before continuing the rest of that script. I was not aware that there were implicit cast nodes. You might not be casting it properly.
Anyways, if the player state is trying to reference itself before getting deleted, it would be strange that it’s returning null. Is this event on the player state itself?
Move the code into the player state, that will prevent the player state from being removed before the event is called.