Forum rules - please read before posting.

Changing data of inactive player in code/custom Action (for player switch purposes)

Hello.

I am trying to implement a custom Action, that would change playerData of a selected player, that is not the current one.

The reason for this is that in our gameplay we can switch from player A to B and then make player A to follow player B. The issue here is that when we switch back to player A, he will go back to where we switched to player B.

I was looking into the function  KickStarter.saveSystem.SaveCurrentPlayerData ()  but was unable to find a way to recreate this for a inactive player.

My Action would receive the player to alter, new coordinates in form of a Marker with prefab ID and the name of the scene we are currently in.

Thank you for any help in advance!

Comments

  • That doesn't sound necessary from your description.  When you switch from Player A to Player B, Player A gets replaced with a "stand-in" NPC A.

    When switching back from Player B to Player A, you should just need to configure the Player: Switch Action to have Player A replace his stand-in automatically.

    The workflow for this is made easier with the v1.64 release, as you can now define an "Associated NPC" for each Player that automatically gets spawned and removed when necessary.  It also addresses some issues with the player-switching feature - which version are you using?
  • I am using v1.63.2.

    Now that I think of it, I might aswell use Replace NPC instead of Restore position.
    Restore position was intended for cross-scene switching, where I can switch via UI. 
    Is for this case any solution? I don't think that replacing NPC is going to work here(or maybe Appear in other scene?).

    Weird is that I am getting an error when trying to switch back to my original character: NullRef AC.Char.get_CanPhysicallyRotate () (at Assets/AdventureCreator/Scripts/Character/Char.cs:3816).
    I do have constant IDs on all objects, but I'll research further.

    Something else: Is it possible to restrict the usage of hotspots(all but one) from a specific player other than manually checking current player with every hotspot?

    As always, I really appreciate your help. Thank you!
  • To answer the original question: it's certainly possible to modify data for the non-active player.

    For an example of this, see the SaveSystem script's AssignItemsToPlayer method, which is used to modify such a player's inventory.  Modifying the position is more simple, and just involves setting the PlayerData class instance's playerLocX, playerLocY and playerLockZ values.

    Please post AC and Unity version numbers as well as the full Console message when reporting errors.

    Hotspots can't be limited by player, but you can create a Cutscene that turns them all on/off accordingly, which runs after switching Player.  See this tutorial for more on how to recycle a ConstantID number so that you avoid having to reference a different Cutscene for each scene.
  • Sorry for the very late answer. I was on vacation.

    Thank you for you hint. We figured that this approach is way to unstable and would probably cause some issues further on.
    So I used switching with NPC instead, like you suggested in your comment above. Thank you!
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.