How to stop a BPs movement from within another BP?

I’m trying to create a blueprint code which will stun an enemy, via stopping their movement and playing an AnimMontage. However, I can’t get the enemy to stop moving. Here are the details:

What I want: I’m making an RPG-style game. I have two character blueprints, one for the player (player), and one for the enemy (troll).

On a special attack, I want the player to be able to stun the troll. I’m using a LineTraceByChannel to check if he hit the troll, and when the troll is damaged by the Line Trace, I want him to be stunned.

What I’ve tried: The obvious way to do this is to cast to the troll, and then stop his movement. I’ve employed both the Stop Movement Immediately and the Deactivate Character Movement functions, but neither seem to have any effect. The troll keeps chasing the player.

Through the use of Print Strings, I’ve been able to determine that I am casting to the troll successfully, and that the code is running through the functions trying to stop the troll. But the troll just keeps coming.

Question: How can I stop a BP’s movement from within another BP?

Below are the relevant screenshots.

This is the troll’s movement. I check to make sure he’s not dead and not attacking, and then move to the player character. If he is attacking, he stops moving. There’s a delay, and then the process re-checks.

This is the code right after the line trace. If the trace hit something, I set the stun target off of the hit actor, apply some damage, and then cast to the troll. I get the troll’s movement component, and try to stop it, but neither the Stop Movement nor the Deactivate functions seem to do anything. Again, I know the cast isn’t failing, so that isn’t the issue.

Why isn’t this working, and how can I fix it?

EDIT: The really strange thing is that sometimes this DOES work. There doesn’t seem to be any consistent pattern, sometimes the troll just stops moving when I hit him. This usually doesn’t happen though.

I copied your setup and it works fine. The fact that it works randomly makes it tough.

Possible issues:

  • Your line trace is not correct
  • You’re not hitting the line trace, check collision settings
  • Try using “Get Movement Component” to use as a ref for stop movement, but it should work as you have it…
  • Use some debugging methods to understand what’s happening. For example, print the name of the “Stun Target” to see if it’s valid when it fails.

Thanks for your reply. I had a script which stopped the troll’s movement when he attacked and restarted it afterwards, and I think what was happening was he was reactivating his movement from that if he swung at me while I was stunning him. A simple Stunned variable and a branch fixed that. Aside from a rotation bug where the troll gets locked facing a certain way after being stunned (also happens randomly), it’s working now.

Yeah I think I got it now. A few unreproducable bugs, but for the most part behavior is how I want it.