Forum rules - please read before posting.

Player Switching also switches GameCamera

I'm not sure if this is a bug, but I recently upgraded to AC 1.64.5 on Unity 2017.2.1p2 and haven't had this happen prior.
I found that GameCameras seem to be "attaching" to players.
For example, let's say I have Player Switching allowed and I have Player1 and Player2.
I start a scene with Player1 with NavCam1 as my GameCamera. Then I Camera:Switch to NavCam2. Then I Player:Switch to Player2. When I Player:Switch back to Player1, the Camera also automatically Switches to NavCam1.
Is there a reason why the Camera is switching along with the Player:Switch without being called?


  • edited September 2018
    I'll need steps to recreate.  What are you doing when switching Player - spawning Player2 in the same scene, or are both Players in different scenes?  Please illustrate as much as you can in the form of screenshots.

    Any related messages in the Console?
  • Player:Switch with Transfer Inventory checked on and the New Player position being Replace Current Player
    I have not changed anything to the flow and it previously worked as expected prior to the upgrade.
  • Here are repro screenshots:
    NavCam focused on my current player, PandaGhost, as expected

    I run Camera:Switch to my zoomed-in camera, ZoomCam. Camera zooms in as expected.

    With my current Camera set to ZoomCam, I Player:Switch to my alternate player character, PandaSkeleton with my New layer position set to Replace Current Player. My new player replaces the current player as expected.

    Camera:Switch back to my default camera, NavCam. Camera zooms back out as expected.

    My next action is strictly a Player:Switch back to my previous player, PandaGhost with my New Player position being Replace Current Player.
    But now notice that this also re-switched my Attached Camera as ZoomCam as if that camera somehow attached itself to my previous player.

    Any clue as to what could be causing this?
    There are no related errors/messages in the console.
  • edited September 2018
    Is this because the last camera state for that player was "ZoomCam" ? So its just reverting to that?

    If you do it the other way round, start with ZoomCam, change to NavCam, switch player to PandaSkeleton, switch camera to ZoomCam, then switch player to PandaGhost - does it revert to NavCam again? Or remain ZoomCam?

    If it switches, its likely just the camera state saved with the Player. 

    Sombebody (Chris?) can probably write a quick bit of code around this if thats whats happening, but maybe just use the "Camera: Revert to previous gameplay" action script straight after switching character?

    Sorry if i'm barking up the wrong tree. :)

    nb. I would expect this behaviour as normal. If I had two characters i'd want them to be able to visit various scenes. So when I switch character, the game reverts to that characters scene/environment. 
  • @KevRev yup, it happens with the inverse as well. it definitely seems like the camera state is saved with the player.

    I just gave it a shot with Camera: Revert to previous gameplay directly after Player:Switch, but all it does is reverses the camera that is "attached" to the player :P 

    Strange why/how the camera is saving itself to the players
  • edited September 2018
    It's actually preferred behaviour. Imagine you moved pandaGhost to another scene then switched back to Panda skeleton. You wouldn't want to manually set up all the camera locations etc. You'd want it to do that for you. Is the switch from ghost to skeleton just a visual thing? Or is it actually two players? If it's just visual (for instance ghost gets electrified and briefly shows skeleton) it may be worth making it an animation you can switch to (different texture/costume) ? Then you never actually switch player, just the animation?
  • Indeed - the state of the camera is saved per-player for the reason @KevRev states.  Normally, switching player would be a case of making a separate character on-screen playable (swapping them with a visually-similar NPC).

    I agree, however, that this may not be desirable when replacing the existing Player.  I'll give some thought to how this might be solved.
  • Thank you both!
    I'll manually swap the camera with a parameter on player switching for the time being.
  • Blah, okay so I'm a little late to this party, but I'm having a similar problem.

    I've got a separate scene for my inventory, so I've decided to preserve the player position per this discussion. by using Player: Switch and a dummy player prefab.

    However, when I Switch: Player (and check Restore Position?) afterwards to get back to the previous scene, my Main Camera's transform position appears to have moved and it no longer registers the attached Nav Cam, which no longer renders & follows the player.

    Screenshots of runtime Main Camera inspector before & after the switch.

    What's the best way to work around this?

  • You'll need to attach a Constant ID component to your NavCam in order to create a saveable reference to it - see the Manual's "Saving scene objects" chapter for more on this topic.

    Is the Console giving a message about this being required?

  • Ah, Chris, you're the best. Adding a Constant ID script to the NavCam worked. Thanks!
    But no, there was no Console message about it being required.

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.
Do NOT follow this link or you will be banned from the site!