# Trying to activate the OnButtonClick through the OnPlayerDamaged

**URL:** <https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, question, fortnite\
**Created:** [November 15, 2024, 6:54pm UTC](https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490 "2024-11-15T18:54:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom\_anderson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tom\_anderson](https://forums.unrealengine.com/u/tom_anderson)\
**Post date:** [November 15, 2024, 6:54pm UTC](https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490/1 "2024-11-15T18:54:57Z")

</div>

I’m trying to activate this knockback event when a player is damaged but I have no idea how to integrate the two

using { /Fortnite.com/Devices }  
using { /Fortnite.com/Playspaces }  
using { /Fortnite.com/Teams }  
using { /Fortnite.com/Game }  
using { /Fortnite.com/Characters }  
using { /Verse.org/Simulation }  
using { /Verse.org/Verse }  
using { /Verse.org/Native }  
using { /Verse.org/Random }  
using { /UnrealEngine.com/Temporary/Diagnostics }  
using { /UnrealEngine.com/Temporary/SpatialMath }

Game\_Manager := class(creative\_device):

```
@editable
MovementButton:button_device = button_device{}

@editable
MM_Mover:creative_prop = creative_prop{}

@editable
MM:movement_modulator_device = movement_modulator_device{}

@editable
PlayerSpawner: player_spawner_device = player_spawner_device{} 

(Prop:creative_prop).ActivateKnockBackEffect(Agent:agent)<suspends>:void =
    if(Fort:=Agent.GetFortCharacter[]):
        option:
            Yaw := Fort.GetViewRotation().GetYawPitchRollDegrees()[0]
            Pitch := 0.0
            Roll := 0.0
            NewRotation := MakeRotationFromYawPitchRollDegrees(Yaw,Pitch,Roll)
            if(Prop.TeleportTo[Fort.GetTransform().Translation - vector3{Z:=120.0},NewRotation]):
              
        Sleep(0.1)
        MM.Activate(Agent)
        Sleep(0.1)
        
        option:
            Prop.TeleportTo[Prop.GetTransform().Translation - vector3{Z:=500.0},Prop.GetTransform().Rotation]
        

OnBegin<override>()<suspends>:void=
    MovementButton.InteractedWithEvent.Subscribe(OnButtonClick)
    PlayerSpawner.SpawnedEvent.Subscribe(OnPlayerSpawned)

OnPlayerSpawned(Agent:agent):void=
    if(FC:= Agent.GetFortCharacter[]):
        FC.DamagedEvent().Subscribe(OnPlayerDamaged)

OnPlayerDamaged(d:damage_result):void=
        if(InstigatorCharacter := fort_character[d.Target],player[InstigatorCharacter.GetAgent[]]):

```

OnButtonClick(Agent:agent):void=  
if(FC:=Agent.GetFortCharacter):  
option:  
MM\_Mover.TeleportTo[FC.GetTransform().Translation, FC.GetTransform().Rotation]  
spawn:  
MM\_Mover.ActivateKnockBackEffect(Agent)

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [November 17, 2024, 10:20am UTC](https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490/2 "2024-11-17T10:20:21Z")

</div>

Why do you need a prop to knockback a player ? Also using an **if** inside an **option** block is wild, didn’t even know it was a thing 😃

---

<div class="post-metadata">

**Author:** ![TheOnlyBobo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheOnlyBobo](https://forums.unrealengine.com/u/TheOnlyBobo)\
**Post date:** [November 18, 2024, 1:01am UTC](https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490/3 "2024-11-18T01:01:42Z")

</div>

A bunch of your code fell outside the format block so its unclear if this is the complete code and also unclear what scope/indent some of it is on — just fyi.

side question - Is it common to use empty IF:s to execute a decide expressions?

```auto
if(Prop.TeleportTo[Fort.GetTransform().Translation - vector3{Z:=120.0},NewRotation]):
# empty?

```

What is the expected behavior and how is it acting now? If you click the button does it knock you back? If this method of player moving is proven then do you have any other verse build errors?

You wrote MM.Activate(), wouldn’t it be MM\_Mover? Did you mean Enable as in creative\_device? Not sure how the build process wouldn’t have brought this to your attention, but maybe you have an MM class level var 🙂

---

<div class="post-metadata">

**Author:** ![tom\_anderson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tom\_anderson](https://forums.unrealengine.com/u/tom_anderson)\
**Post date:** [November 18, 2024, 9:56am UTC](https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490/4 "2024-11-18T09:56:28Z")

</div>

using { /Fortnite.com/Devices }  
using { /Fortnite.com/Playspaces }  
using { /Fortnite.com/Teams }  
using { /Fortnite.com/Game }  
using { /Fortnite.com/Characters }  
using { /Verse.org/Simulation }  
using { /Verse.org/Verse }  
using { /Verse.org/Native }  
using { /Verse.org/Random }  
using { /UnrealEngine.com/Temporary/Diagnostics }  
using { /UnrealEngine.com/Temporary/SpatialMath }

Game\_Manager := class(creative\_device):

```
@editable
MovementButton:button_device = button_device{}

@editable
MM_Mover:creative_prop = creative_prop{}

@editable
MM:movement_modulator_device = movement_modulator_device{}

@editable
PlayerSpawner: player_spawner_device = player_spawner_device{} 

(Prop:creative_prop).ActivateKnockBackEffect(Agent:agent)<suspends>:void =
    if(Fort:=Agent.GetFortCharacter[]):
        option:
            Yaw := Fort.GetViewRotation().GetYawPitchRollDegrees()[0]
            Pitch := 0.0
            Roll := 0.0
            NewRotation := MakeRotationFromYawPitchRollDegrees(Yaw,Pitch,Roll)
            if(Prop.TeleportTo[Fort.GetTransform().Translation - vector3{Z:=120.0},NewRotation]):
              
        Sleep(0.1)
        MM.Activate(Agent)
        Sleep(0.1)
        
        option:
            Prop.TeleportTo[Prop.GetTransform().Translation - vector3{Z:=500.0},Prop.GetTransform().Rotation]
        

OnBegin<override>()<suspends>:void=
    MovementButton.InteractedWithEvent.Subscribe(OnButtonClick)
    PlayerSpawner.SpawnedEvent.Subscribe(OnPlayerSpawned)

OnPlayerSpawned(Agent:agent):void=
    if(FC:= Agent.GetFortCharacter[]):
        FC.DamagedEvent().Subscribe(OnPlayerDamaged)

OnPlayerDamaged(d:damage_result):void=
        if(InstigatorCharacter := fort_character[d.Target],player[InstigatorCharacter.GetAgent[]]):
           
OnButtonClick(Agent:agent):void=
            if(FC:=Agent.GetFortCharacter[]):
                option:
                     MM_Mover.TeleportTo[FC.GetTransform().Translation, FC.GetTransform().Rotation]
                spawn:
                    MM_Mover.ActivateKnockBackEffect(Agent)

```

Yes, when you click the button it knocks the player back (well forward at the moment and I’m working to fix that), I’m trying to activate this “knockback” when a player is damaged through -

```
OnPlayerSpawned(Agent:agent):void=
    if(FC:= Agent.GetFortCharacter[]):
        FC.DamagedEvent().Subscribe(OnPlayerDamaged)

OnPlayerDamaged(d:damage_result):void=
        if(InstigatorCharacter := fort_character[d.Target],player[InstigatorCharacter.GetAgent[]]):

```

and I’m not sure how to get it working  
note - no current verse build errors

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [November 18, 2024, 2:05pm UTC](https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490/5 "2024-11-18T14:05:40Z")

</div>

> [@TheOnlyBobo](#):
>
> Is it common to use empty IF:s to execute a decide expressions?

Sadly it is, I never use it because I find it dumb but a lot of creators use that syntax

---

<div class="post-metadata">

**Author:** ![TheOnlyBobo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheOnlyBobo](https://forums.unrealengine.com/u/TheOnlyBobo)\
**Post date:** [November 26, 2024, 5:40am UTC](https://forums.unrealengine.com/t/trying-to-activate-the-onbuttonclick-through-the-onplayerdamaged/2125490/6 "2024-11-26T05:40:38Z")

</div>

> [@tom\_anderson](#):
>
> `if(InstigatorCharacter := fort_character[d.Target],player[InstigatorCharacter.GetAgent[]]):`

Pretty sure your logic is failing at this spot ^ Add your call to  
MM\_Mover.ActivateKnockBackEffect(agent) under that if:

- Those static variables `InstigatorCharacter := ..` inside this if expression are only accessible within the scope of the proceeding block, what was the goal with this line of code?
- You cast it as player but never use it `player[InstigatorCharacter.GetAgent[]]`

I didn’t test it specifically but try something like this?

```auto
OnPlayerDamaged(d:damage_result):void=
    if(InstigatorCharacter := fort_character[d.Target], Player:= player[InstigatorCharacter.GetAgent[]]):
        MM_Mover.ActivateKnockBackEffect(Player)

```

^ added Player := assignment && Activate call

edit: Not sure its a great “Pattern” long term but to answer the question / title specifically you could pretend to be a button and call OnButtonClick() there too
