Forum rules - please read before posting.

player.ID is always -1

I have noticed the (spawned) player.ID is always -1, meaning its value is not copied from PlayerPrefab when spawning.

Is this really intended?

The problem I am facing is that in order to create a call to ActionPlayerTeleportInactive I need the Player.ID, but I have the name, so traversing KickStarter.settingsManager.players may fail because playerOb can be null in I do not know which conditions. So I really have no secure way to find a player id given its name.

As fallback, I look for all the player in the scene, but the ID is always -1. I guess that playerOb wont be null if the player is in the scene, but it is my guess only.

Is there any way to get a player Id given its name? (the one that appears in the inspector: gameObject.name)

Thanks in advance!

Comments

  • Are you spawning players through script, or allowing AC to handle it automatically?

    What is your AC version? I can't recreate this issue.

    When AC spawns a Player, the PlayerPrefab class calls the Player's SpawnFromPrefab function, which passes the ID value to set.

  • AC Version: 1.75.5 (sorry, I always forget to mention it)
    Unity version: 2021.3.0f1

    I am letting AC to handle it.

    I might be completely wrong, maybe I am looking into the wrong variable. Here is an screenshot:

  • Your script's player variable is of the type PlayerPrefab, which is a data container and separate to the Player class that's present in the scene at runtime.

    Details on this class can be found here in the Scripting Guide.

    To get the ID of the player from this variable, you'd call:

    Player playerInstance = player.GetSceneInstance ();
    if (playerInstance)
    {
        int playerID = playerInstance.ID;
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.