Play montage on Enemy AI throwing player character error

I have two characters and when the first character attacks my referee AI everything is fine. Those attacks are also done by a box trace for main attack and a collision detection for the charge attack. But when my second player character attacks which is using a projectile it throws this error, (Blueprint Runtime Error: “Accessed None trying to read property K2Node_DynamicCast_AsChief”. Blueprint: RefereeEnemy Function: Execute Ubergraph Referee Enemy Graph: EventGraph Node: Play Montage). It only does it on this AI and only when the second character attacks.

285283-untitled.png

The other two enemy AI are setup exactly the same as this one, in reference to the montage obviously, but this one is the only one that throws the error when attacked by the second characters projectiles. I can even approach the enemy without attack and he will attack and play the montage all the same. It only procs the error when the second player attacks this enemy. Any suggestions?

The error you’re receiving is inside the RefereeEnemy Blueprint. The provided message means that you’re attempting to access an invalid reference in a type cast and this raises the error you’re describing. I don’t think that the provided screenshot has something to do with that so can you show us where you’re attempting to type cast?

That’s just the thing I cast in begin play and those references are only used once when the player kills the referee in event any damage. And like I said the other 2 AI I have are setup exactly the same. I can even damage the referee and kill them with the chief character with no issue its only when the second players projectile hits the referee that it throws this error.

You mention that you have a second player, however in the provided image you get the reference of the character with player index 0 (meaning the first player). To get a reference of your second player try to provide an index of 1.

Two characters to chose from

If it helps, when I remove the play montage from the line it throws the same error only on a name variable that I’m setting in event any damage.

So after further exploration I have tracked the issue (I think) down to this branch node here

It’s strange I know, but I can hook up everything even event melee into the play montage, I can even bypass the branch and just not do the referee life check and go straight into the rest of the code and even kill the referee without issue. But the second I hook up the branch node it throws the error for the dynamic cast with chief on play montage. Maybe an unreal dev has an idea? I wouldn’t even know how to get their attention.

Have you verified that your Player Character is indeed a type of “Chief” and the pure cast you have there is successful?

Yes. In the node just after the branch I have a function that decreases the players special recharge time and in there I use the variables set in begin play. I can bypass the branch and have everything hooked up and I’m fine.

Update! I reconnected the branch node but left the Boolean check unconnected and it worked fine but as soon as I connect it back same problem. Still have no idea as to why its throwing that error on the play montage though. Cause if I disconnect that it just throws that error elsewhere anyhow.

Bump for answer

Ok so I’m an idiot. As per usual the answer was simple and per the laws of coding, the simpler the issue is the more complicated the search to fix it becomes.

So currently the first time anything hits the ref that branch goes false because his health is still greater than zero. So when I was doing that the first thing it tries to do in the old image was run a delay that’s based off of chiefs charge duration but because this was not chief it didn’t know what it was looking for on the first hit. So I just added another branch that checks my name variable I set in the beginning and it’s all good now. WOW! I’m just gonna sit here for a min with my head down in shame cause I feel monumentally stupid.