Accessed none problem, can't set boolean again?

So I’m making a game here you have to protect sheep from ravenous wolves trying to steal them away. I have a wolf ai set up that allows them to enter the pen, take a sheep, leave the pen and escape the map. I even set things up so once a wolf as picked a sheep, no other wolf will go after that sheep because it’s been marked as taken.

Buuuut this could lead to some stupid behavior. Say a wolf selects the closest non-marked sheep to them, but while moving to it, another sheep becomes closer. They would ignore the closer sheep for the originally marked one. The system still functions, but this is dumb behavior I’d like to fix.

Sooooo I tried having the wolf update their selection every whole second. The problem is that once the boolean for “already selected” was set to positive by the ai, but then set to negative when finding a new sheep, the new sheep selected wasn’t being set as marked. The result is having wolves chasing after the same sheep again. After gameplay, I get that notorious “accessed none” error.

I had a similar problem earlier when “already selected” wouldn’t be set by the find sheep function (that is, it refused to set the boolean from inside the loop even from the “completed” pin), so I placed that action outside of the function in the regular ai blueprint. This made setting the boolean work. I tried moving the “set already selected to false” in the same place, but this didn’t fix it. I tried setting a “previous sheep” and setting the previous sheep’s bool using that, but I get the same error. It only likes to set the bool once. After that, it refuses to play ball anymore.

This problem is unavoidable becaaaause the player can prevent the wolf from escaping with your sheep by smacking them with a stick. When you do this, they drop their sheep and stumble. After this, they need to select a new sheep, rather than chasing the same sheep like an idiot even though you’re beating on them.

Here’s a look at the relevant nodes. :o

If you’re using AI to try and find the closet item, then the best way to do it is EQS (Environment Query System) -

https://docs.unrealengine.com/latest/INT/Engine/AI/EnvironmentQuerySystem/

In that you could just get all actors of a class then score them based on distance to the querier. Try setting that up and seeing if that fixes your issues. I don’t entirely understand that node setup if you try to unset something from an actor that has been destroyed it will return none for the target, so at some point you’re referencing something that no-longer exists within the level.