# Why is my Custom Player not being found?

**URL:** <https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [January 10, 2025, 1:03am UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833 "2025-01-10T01:03:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rastarocket1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rastarocket1/32/1015784_2.png) [@Rastarocket1](https://forums.unrealengine.com/u/Rastarocket1)\
**Post date:** [January 10, 2025, 1:03am UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/1 "2025-01-10T01:03:18Z")

</div>

I am trying to code a GUI with buttons that Set the class for the player. However my Custom Player object is not found when I try it out although it works when I press a button to assign the class:

```
ClassSetter(Agent:agent):void=
    if(IsAgent:agent = agent[Agent]):
        if(CP:CustomPlayer = PlayersMap[Agent]):
            CP.SetClass(6)
            Print("Class Set")
        else:
            Print("Player is not a custom object")

```

(This was in the Game Manager Script)  
In the Script of the UI I have the following code to send the agent to the function:

```
Interface := class():

   var MainCanvas : canvas = canvas{}
   var AbilityButton1 : button_loud = button_loud{}
   var AbilityButton2 : button_loud = button_loud{}
   var AbilityButton3 : button_loud = button_loud{}

   var GM: game_manager = game_manager{}

   ToMessage<localizes>(String : string) : message = "{String}"

   AddUI(Agent:agent):void=
       if(Player := player[Agent],PlayerUI := GetPlayerUI[Player]):
           set MainCanvas = CreateUI()
           PlayerUI.AddWidget(MainCanvas, player_ui_slot{InputMode := ui_input_mode.All})

        

   AbilityHandler(Message : widget_message):void=
       Player := Message.Player
       if(PlayerUI := GetPlayerUI[Player]):
           PlayerUI.RemoveWidget(MainCanvas)        
       if(Agent:agent = agent[Player]):
           GM.ClassSetter(Agent)

```

I am really confused because I am using the same code and don’t understand why it wouldn’t work, also sorry for bad formatting, I am writing on my phone at 1:30 AM 😬  
I would really appreciate it if some1 could help me, thanks in advance 😃

---

<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:** [January 10, 2025, 8:45am UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/2 "2025-01-10T08:45:33Z")

</div>

Can you fix your post syntax please

---

<div class="post-metadata">

**Author:** ![Rastarocket1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rastarocket1/32/1015784_2.png) [@Rastarocket1](https://forums.unrealengine.com/u/Rastarocket1)\
**Post date:** [January 10, 2025, 11:33am UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/3 "2025-01-10T11:33:43Z")

</div>

Fixed it, thank you 😃, I still need help tho please

---

<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:** [January 10, 2025, 12:40pm UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/4 "2025-01-10T12:40:35Z")

</div>

How do you populate your PlayersMap ?

---

<div class="post-metadata">

**Author:** ![Rastarocket1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rastarocket1/32/1015784_2.png) [@Rastarocket1](https://forums.unrealengine.com/u/Rastarocket1)\
**Post date:** [January 10, 2025, 12:50pm UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/5 "2025-01-10T12:50:43Z")

</div>

Like this:

```
OnPlayerSpawned(MaybeAgent:?agent):void=
    Print("PlayerSpawnedIn")
    if(Agent:= MaybeAgent?):
        if(PlayerExists := PlayersMap[Agent]):
        #Found Player
        else: 
            CP:CustomPlayer = CustomPlayer{MyAgentObj := Agent}
            option:
                set PlayersMap[Agent] = CP

```

Is this what you need? My Custom Player class would be this if you need it:

```
CustomPlayer := class():
    MyAgentObj:agent

    var Class<private>:int = 1

    SetClass(C:int):void=
        set Class = C

    GetClass():int=
        return Class

```

Thank you for your help 😃

---

<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:** [January 10, 2025, 12:59pm UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/6 "2025-01-10T12:59:03Z")

</div>

The OnPlayerSpawned method is probably called after the UI is being added

---

<div class="post-metadata">

**Author:** ![Rastarocket1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rastarocket1/32/1015784_2.png) [@Rastarocket1](https://forums.unrealengine.com/u/Rastarocket1)\
**Post date:** [January 10, 2025, 1:04pm UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/7 "2025-01-10T13:04:17Z")

</div>

I thought of this so I added a time of 3 seconds before my interface is created:

```
ChooseAbilities()<suspends>:void=
    Sleep(3.0)
    Players:=GetPlayspace().GetPlayers()
    for(Player:Players):
        if(IsAgent:agent = agent[Player]):
            var NewGUI : Interface = Interface{}
            NewGUI.AddUI(IsAgent)

```

However it doesn´t work that way, how could I fix it instead?

---

<div class="post-metadata">

**Author:** ![Rastarocket1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rastarocket1/32/1015784_2.png) [@Rastarocket1](https://forums.unrealengine.com/u/Rastarocket1)\
**Post date:** [January 11, 2025, 6:13pm UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/8 "2025-01-11T18:13:13Z")

</div>

Found a Workaround by passing the Custom Player to the Interface Class 🙂

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [February 10, 2025, 6:13pm UTC](https://forums.unrealengine.com/t/why-is-my-custom-player-not-being-found/2268833/9 "2025-02-10T18:13:14Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
