Forum rules - please read before posting.

Switch Player

edited June 2023 in Engine development

I'm working on a 2D game which I have multiple Player Characters. I followed this tutorial (https://adventurecreator.org/tutorials/switching-between-multiple-player-characters), but I'm encountering some issues when attempting to display my Player1 in Scene B.

In Scene B's OnStart, I've set the Player: Switch and Player: Teleport inactive. However, if I run the game directly from Scene B, both Player0 and Player1 appear simultaneously.

If I run the game from the preceding scene, only Player1 is displayed, but the transition from Player0 to player1 is very noticeable.

Any help would be appreciated.

I've checked Replace old Player's position in Player: Switch, and now Player0 no longer appears.

This situation leads me to question Player:Teleport inactive. I've set New scene index in Player:Teleport Inactive to scene A. If I navigate to scene A, Player0 is absent, but my active player is now Player1.

Q. Under these circumstances, where might I locate my Player0?
Q. How can I switch Player in a specific scene only? :
I've assigned Player1's Starting Point to Scene B. However, if run Unity from Scene B and go back to previous scenes, my player becomes Player1 not Player0.

Thank you so much in advance for your help.

Comments

  • Could you share details on exactly how you want your player-switching mechanic to work?

    Generall speaking, the Replace old Player's position option is intended for costume changes - where it's narratively the same character, only they use a different prefab. If your characters are separate, leave this unchecked.

    You should also avoid using the Player: Switch Action in your OnStart cutscenes. Switching Player will also switch the game to the scene they're in. If you want to switch the Player to a specific scene, the workflow should be:

    • Use the Player: Teleport inactive Action to teleport the new Player to the correct scene (if not there already)
    • Use the Player: Switch Action to then switch to them. A separate Scene: Switch Action is not necessary

    Your game's default Player will always begin in the first scene of your game.

  • edited June 2023

    Thank you so much, Chris! To answer your question, my game has several chapters, and in certain chapters, my Player Character transforms into different creatures. Thus, the 'Replace old Player's position' option seems suitable for me since I have, narratively, the same Player Character, but they use a different prefab.

    My misunderstanding - I didn't realize that 'Player: Teleport inactive' is used to teleport the new Player. I initially thought it was for another Player that I didn't want to use in the scene. Similarly, I wasn't aware that I didn't need 'Scene: Switch' when I use 'Player: Switch'. I will revise my action flows accordingly and try again.

  • edited June 2023

    Hi there,

    Just to recap my situation, I have two scenes, Scene A and Scene B, as well as two Player Characters: Player0 and Player1. I want Player0 to be in Scene A and Player1 to be in Scene B when my audience clicks a Door Hotspot in Scene A.

    I've made some adjustments based on the feedback, I placed the following Actions in the Door Hotspot in Scene A:

    Player: Teleport inactive
    Player: Player1
    New scene name: Scene B

    Player: Switch
    New Player: Player1
    Transfer inventory?: checked (because Player1 and Player0 are narratively the same character)

    When I hit 'Play' and click the Door Hotspot from Scene A, the scene switches to Scene B, but it doesn't execute the Actions in 'OnStart' (I have Object: Teleport Action, 'IsPlayer' checked, and Player is Player1). Player1 walks when I click on the ground (NavMesh).

    If I hit 'Play' from Scene B, the 'OnStart' Actions execute, but both Player 0 and Player 1 show up at PlayerStart2D. And If I click on the ground (NavMesh), then Player0 starts walking

    Any help in identifying where I've gone wrong would be greatly appreciated. Was I supposed to exclude any actions related to Player1 in 'OnStart'?

  • If Player1 is always in Scene B, you might not need to run the Player: Teleport inactive Action. Any non-default Player listed in the Settings Manager can have their starting scene/position data set by clicking the cog icon to the right of their prefab field.

    the scene switches to Scene B, but it doesn't execute the Actions in 'OnStart'

    This can be a bit tricky - but in the case of a scene opening due to a Player-switch, either OnStart or OnLoad will run based on whether the new Player already has data associated with it (as will be the case in using the above Action).

    The easier way to deal with this is to bypass the OnStart/OnLoad cutscene fields in the Scene Manager, and instead use the ActionList Starter component.

    Keep your OnStart cutscene, but clear it from the Scene Manager. Then attach this new component to the cutscene GameObject. In its Inspector, check both Run on scene start?, Run on scene load?.

    If Player-switching is enabled, this Inspector will then also show a Scene load condition field. Set this to Due To Switching Player, and it will always run in your described situation.

    If I hit 'Play' from Scene B, the 'OnStart' Actions execute, but both Player 0 and Player 1 show up at PlayerStart2D. And If I click on the ground (NavMesh), then Player0 starts walking

    This is because Player0 is your default Player - and will be spawned in whichever scene you begin Play Mode from.

    If you want to begin the game from Scene B, with Player1 in control, you'd also need to set Player1 as the default - which you can do via the cog menu beside their prefab field in the Settings Manager.

  • Thank you so much, Chris! The ActionList Starter works perfectly! The reason I started the game from Scene B was purely for testing purposes. If there are no problems controlling Player1 through clicking when I start playing the game from the beginning, then there's no issue. Thanks 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.