Forum rules - please read before posting.

Upgrading from 1.75 to 1.79, Player::SpawnFromPrefab Removed

Hello all!

I recently upgraded from 1.75 to 1.79 for the latest and greatest, and I went through the changelog + upgrade notes to see if there were any relevant bits associated with the error I'm seeing, but was unable to find details. I also checked the forums for "SpawnFromPrefab", but only saw two old posts, so I need an adult :)

Here's my code block, with context, and I understand that the error is due to the fact that the method has been removed, but I'm not sure what replaced it's functionality (or if there is now a better / different way of going about this). Seemed to work fine in 1.75.x, but I understand things shift rapidly and for good reason in the product.

I have a character selection screen where you can select your player class/model/attributes and preview it before entering into the game. This function sets up the preview screen every time the player chooses a different class (via button click). The first parameter takes in the prefab for a warrior, mage, or thief with the Player script attached. I don't believe the other parameters are important to the question.

void PreviewPlayerSetup(Player selectedPlayer, int playerID, int abilityID)
{
    ResetStats();
    PlayerData currentData = KickStarter.saveSystem.GetPlayerData(KickStarter.player.ID);
    KickStarter.player.RemoveFromScene();
    KickStarter.player = selectedPlayer.SpawnFromPrefab(playerID);
    KickStarter.player.LoadData(currentData);
    KickStarter.player.downMovementLocked = true;
    KickStarter.player.upMovementLocked = true;
    KickStarter.player.leftMovementLocked = true;
    KickStarter.player.rightMovementLocked = true;
    GlobalVariables.SetIntegerValue(abilityID, 5);
}

And, of course, the error:

'Player' does not contain a definition for 'SpawnFromPrefab' and no accessible extension method 'SpawnFromPrefab' accepting a first argument of type 'Player' could be found (are you missing a using directive or an assembly reference?)

Please let me know if you need any more details, thank you for the assistance, and happy holiday seasons!

Very respectfully,
Tyler

Comments

  • edited November 2023

    Apologies for the hassle. For streamlining, this function was moved to the SpawnPlayerCo coroutine in the PlayerSpawner helper class, which also handles the loading of its data:

    This function is now a co-routine. The literal equivalent would be to call:

    PlayerPrefab playerPrefab = KickStarter.settingsManager.GetPlayerPrefab (playerID);
    StartCoroutine (KickStarter.playerSpawner.SpawnPlayerCo (playerPrefab, null);
    

    However, the "intended" way to handle spawning is to let AC handle the Player's presence based on their data. If you also set the movement locks as part of this data, then they too will be applied automatically:

    PlayerData playerData = KickStarter.saveSystem.GetPlayerData (playerID);
    playerData.playerLeftLock = true; // etc
    playerData.currentScene = gameObject.scene.buildIndex;
    KickStarter.playerSpawner.UpdatePlayerPresenceInScene (playerData, callback);
    

    Though - if it was working as intended before - it may be best to simply run the exact same code as before:

    Player newInstance = Instantiate (selectedPlayer);
    newInstance.gameObject.name = selectedPlayer.gameObject.name;
    newInstance.ID = playerID;
    KickStarter.eventManager.Call_OnPlayerSpawn (newInstance);
    
  • No worries, and I appreciate the response! I'll give each suggestion a try, weigh the outcomes against my needs, and let you know if I run into any trouble. Thank you, again!

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.