Invalid actor reference passing through IsValid node

i’m receiving the following error :

Blueprint Runtime Error: “Attempted to access ZombieBP_C_20 via property K2Node_ComponentBoundEvent_Actor, but ZombieBP_C_20 is pending kill”. Blueprint: ZombieAIcontroller Function: Execute Ubergraph Zombie AIcontroller Graph: EventGraph Node: Branch

And this is the branch node accesing the actor reference.

Possibly because you’re using pure cast.

Hey, thanks for the reply.
I changed to impure cast, Unfortunately i still receive the error.

Yes, the actor is getting destroyed after some time. But before destroying the actor i detach the controller.

Do you destroy the actor when setting the IsDead bool? I might be wrong, but I think since the actor is still referenced in memory until it’s cleared by the garbage collector, it’s still valid, but it’s Pending Kill, so it’s no longer accessible.

So you’re detaching the controller, and then you try getting controlled pawn? Maybe that’s the issue?

Thats the point, if i detach the controller, why the controlled pawn reference is passing through IsValid? By the way even if i dont use the Detach node i still have the error.

Validate controlled pawn first, then try to cast.

Still the same. I tried using IsValid on all references, but the error still persist.

I’ve checked it. After detaching from controller, Get Controlled Pawn seem to continue returning something that passed validation, but you can’t get any data from it.

Maybe you should find another way to do what you need, e.g. with death events.

Ok , so before detaching and destroying the actor i destroyed the AIPerception component on controller sinse the event “On Target Perception Updated” of this component is the initial cause of the error. My idea is to prevent the component to fire the event when the actor is dead. But i dont know why, the event is still firing even after destroying the component.