The easy fix is to add a “Is Valid” node from the Pawn node in the OnSeePawn event. Only if the Pawn is valid, proceed with the rest. This will clear the error.
Assuming you are quitting from a game state where the Leader and player exist. Also assuming that your error is generated by the quitting action.
My guess is that the callback for the AI move is being fired after part of the cleanup from quit has scrapped the casting to MainPlayer_C, which unreal then tries to access, but cannot due to the cleanup.
I’m no professional but that’s just what I see from the blueprint + your description
I would start by breaking your blueprint into parts until you can isolate where exactly the failure is occurring. Once you have isolated the point of failure, figure out what exactly in that card is causing the failure. Be as surgical as you can so you know exactly what is going on. The error looks to be caused by Unreal trying to reference a variable assigned for cleanup.
It’s returning that error because of “AI Move To”. I can break apart any of the blueprints from the “AI Move To” and it will work and not return the error. So, I’m not sure how exactly can I fix it so that the AI Move To still does its job.
Now that I see it again, try to add IsValid to the Leader reference that goes into the AI Move To. Also, you dont need to add the actor reference and the location at the same time - you can pick just one :).
You need to plug in the Is Valid node so it executes Go from OnSeePawn → Is Valid → CastToMainPlayer.
What I mean is that you can just plug in Leader to Target Actor and disconnect Location. Or vice-versa. The AI will move to either a specific location or the location of a target actor. Right now you are providing both. Disconnect one and see!