# Can someone help me apply a visual\_effect\_powerup\_device on player spawn?

**URL:** <https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [April 1, 2023, 10:25pm UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006 "2023-04-01T22:25:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matakage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/matakage/32/642662_2.png) [@Matakage](https://forums.unrealengine.com/u/Matakage)\
**Post date:** [April 1, 2023, 10:25pm UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/1 "2023-04-01T22:25:23Z")

</div>

This is what I’ve been trying, and it’s not working. I’m not sure why I can’t associate subscribe from the “OnPlayerSpawn” part to the “GrantVisualEffect” part.

```auto
    @editable
    var PlayerSpawners : []player_spawner_device = array{}

    @editable
    PlayerVisualEffect : visual_effect_powerup_device = visual_effect_powerup_device{}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        set ElimsToEndGame = WeaponGranters.Length;
        InitPlayers()

    InitPlayers() : void=
        AllPlayers := GetPlayspace().GetPlayers()
        for (Player : AllPlayers, FortCharacter := Player.GetFortCharacter[]):
            if (set PlayerMap[Player] = 0, WeaponTier := PlayerMap[Player]):
                FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated)
                GrantWeapon(Player, WeaponTier)
    
    OnPlayerSpawn(Player : player) : void=
        Print("Player spawning")
        for (PlayerSpawned : PlayerSpawners):
            PlayerSpawned.SpawnedEvent.Subscribe(GrantVisualEffect)

    GrantVisualEffect(Agent : ?agent) : void=
        if (Player := Agent?):
            PlayerVisualEffect.Pickup(Player)

```

The error is at the last part of the OnPlayerSpawn section with (GrantVisualEffect) underlined in red. The error message reads:  
“This function parameter expects a value of type agent-\>void, but this argument is an incompatible value of type ?agent-\>void.(3509)”

Thanks!

---

<div class="post-metadata">

**Author:** ![Matakage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/matakage/32/642662_2.png) [@Matakage](https://forums.unrealengine.com/u/Matakage)\
**Post date:** [April 1, 2023, 10:31pm UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/2 "2023-04-01T22:31:59Z")

</div>

Since it didn’t show the errors, the red underline is under (GrantVisualEffect), the last part of the OnPlayerSpawn part.

---

<div class="post-metadata">

**Author:** ![alphh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alphh/32/637108_2.png) [@alphh](https://forums.unrealengine.com/u/alphh)\
**Post date:** [April 1, 2023, 11:09pm UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/3 "2023-04-01T23:09:30Z")

</div>

Try changing your GrantVisualEffect function to this!

```auto
GrantVisualEffect(Agent : agent) : void=
        if (Player := Agent):
            PlayerVisualEffect.Pickup(Player)

```

I dont think it’s possible for the PlayerSpawner SpawnedEvent to return without a Player/Agent (I’m not sure which it returns!), so it’s not necessary to use a ?

_(This is my first time attempting to help someone here! I don’t know too much and I could be wrong, good luck though!)_

---

<div class="post-metadata">

**Author:** ![Matakage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/matakage/32/642662_2.png) [@Matakage](https://forums.unrealengine.com/u/Matakage)\
**Post date:** [April 1, 2023, 11:46pm UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/4 "2023-04-01T23:46:15Z")

</div>

Thanks for the help! I’m open to anything ideas, including a completely different way applying an effect on a player spawn. Unfortunately, the edit you suggested underlined “(Player := Agent):” on that second line you posted with the error message “Expected an expression that can fail in the ‘if’ condition clause(3513)” It did make the previous red underline go away, though!

---

<div class="post-metadata">

**Author:** ![Syz\_n](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syz\_n](https://forums.unrealengine.com/u/Syz_n)\
**Post date:** [April 2, 2023, 12:07am UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/5 "2023-04-02T00:07:23Z")

</div>

in the if statement you’re not testing anything  
i assume you wanna test if agent is a player so i would write it as

```auto
# tests if agent is a player. typecast Agent to player
# if the cast is successful then grant the powerup
if (Player := player[Agent]):
    PlayerVisualEffect.Pickup(Player)

```

---

<div class="post-metadata">

**Author:** ![Matakage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/matakage/32/642662_2.png) [@Matakage](https://forums.unrealengine.com/u/Matakage)\
**Post date:** [April 2, 2023, 1:15am UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/6 "2023-04-02T01:15:59Z")

</div>

Thanks, that resolved the error! Unfortunately, the visual effect is still not applying at spawn! Well, I’ll keep looking for new approaches, and thanks for your help anyway.

---

<div class="post-metadata">

**Author:** ![Syz\_n](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syz\_n](https://forums.unrealengine.com/u/Syz_n)\
**Post date:** [April 2, 2023, 1:35am UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/7 "2023-04-02T01:35:06Z")

</div>

is `OnPlayerSpawn(Player : player) : void=` called somewhere?  
if not then all your player spawners aren’t being subscribed to.  
which would mean GrantVisualEffect is never called

---

<div class="post-metadata">

**Author:** ![Matakage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/matakage/32/642662_2.png) [@Matakage](https://forums.unrealengine.com/u/Matakage)\
**Post date:** [April 2, 2023, 1:38am UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/8 "2023-04-02T01:38:59Z")

</div>

```auto
OnBegin<override>()<suspends>:void=
        set ElimsToEndGame = WeaponGranters.Length;
        InitPlayers()
        OnPlayerSpawn

```

I put it here, but I’m not really sure if that’s calling it. Is there a better place or way to call it?

---

<div class="post-metadata">

**Author:** ![Syz\_n](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syz\_n](https://forums.unrealengine.com/u/Syz_n)\
**Post date:** [April 2, 2023, 1:53am UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/9 "2023-04-02T01:53:08Z")

</div>

since you’re not passing anything into `OnPlayerSpawn` i would update it  
like  
`OnPlayerSpawn() : void=`

now you should be able to call it like

```auto
OnBegin<override>()<suspends>:void=
        set ElimsToEndGame = WeaponGranters.Length;
        InitPlayers()
        OnPlayerSpawn()

```

---

<div class="post-metadata">

**Author:** ![Matakage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/matakage/32/642662_2.png) [@Matakage](https://forums.unrealengine.com/u/Matakage)\
**Post date:** [April 2, 2023, 3:19am UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/10 "2023-04-02T03:19:24Z")

</div>

Hey, that worked! thanks! And most importantly I learned something. I get what you mean by “nothing being passed into it” so I should have left it blank. I appreciate the help!

---

<div class="post-metadata">

**Author:** ![Syz\_n](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syz\_n](https://forums.unrealengine.com/u/Syz_n)\
**Post date:** [April 2, 2023, 3:42am UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/11 "2023-04-02T03:42:50Z")

</div>

no problem, when i replicated it i noticed its firing at the beginning as well. i would put a `Sleep` to avoid giving the players the powerup when the game starts. unless thats what you want as well

```auto
OnBegin<override>()<suspends>:void=
        set ElimsToEndGame = WeaponGranters.Length;
        InitPlayers()
        Sleep(1.0)
        OnPlayerSpawn()

```

---

<div class="post-metadata">

**Author:** ![Matakage](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/matakage/32/642662_2.png) [@Matakage](https://forums.unrealengine.com/u/Matakage)\
**Post date:** [April 2, 2023, 6:51pm UTC](https://forums.unrealengine.com/t/can-someone-help-me-apply-a-visual-effect-powerup-device-on-player-spawn/838006/12 "2023-04-02T18:51:04Z")

</div>

Ahh cool, thanks. I do want it to be applied at start as well, but it’s always helpful to learn more about functionality in case I need it later, so I appreciate that.
