Forum rules - please read before posting.

Switching players strange behaviour

edited July 2019 in Technical Q&A

Hello, I have been doing the tutorial about switching between two players and switching mid game. I have done everything according to the tutorial. I have not understood or found the part :

NOTE: To have the NPCs run the same Interactions regardless of which scene they're in, set their Hotspots' Interaction source fields to Asset file so that Interactions will rely on ActionList assets instead of scene-based actionlists.

My ActionList when I click on a button I have made to Switch player is this :

https://imgur.com/sHCGInd

*I have checked the Restore Position unlike how it is shown in the image.

When I start the scene I get my Player and an NPC positioned to a specific location. I then move my player a bit and hit the Switch button. After that I suddenly have 3 models in my scene. One is an NPC ( my former player) another one is the new player (the switched one) and then there is a third model which is the same as my new player which is located at a random (it appears) position.

I then move my second player and hit again the switch button to switch back to my first player i had when I first run the scene. The switch is done correctly I get control of him at the location he was placed but now the previous player which is now NPC is placed on the initial position that I have him assigned at the beginning of each scene, where he should have been placed at the position that I left him at the moment I made the switch to the other player.

Also the third model has disappeared. If I press Switch again the same thing happens all over again.

Comments

  • To have the NPCs run the same Interactions regardless of which scene they're in, set their Hotspots' Interaction source fields to Asset file so that Interactions will rely on ActionList assets instead of scene-based actionlists.

    The Interaction source field can be found on the Hotspot component.

    After that I suddenly have 3 models in my scene.

    I cannot recreate such behaviour - what are your AC and Unity version numbers, and what GameObject exactly is the third (erroneous) model? Is it a Player or an NPC. I'm assuming that the first two are positioned correctly.

    What messages appear in the Console window at this time? Let's also see screenshots of the full Inspectors of both character's Player and associated NPC prefabs.

  • edited July 2019

    I again don't undestand the hotspot component, you mean on every item that I have in the game which uses a hotspot? There is no hotspot component on player or NPCs.

    What you asked for:

    AC Ver 1.68.3 - Unity Ver 2019.1.6f1
    I have two characters Malcolm ( default player ) and Liam (2nd player )

    I run the scene according to the tutorial having only the prefab of Liam NPC visible.

    When I change from the default player (Malcolm) to Liam the 3rd model is Liam NPC.

    The only relevant thing on the console is a warning :

    NPC 'Liam NPC' was moved out of the way to make way for the associated Player 'Liam'.

    The Inspector of Malcom (player 1), Malcom NPC, Liam (player 2), Liam NPC : https://imgur.com/a/B0anv0T

    @ChrisIceBox YouTube:

  • There is no hotspot component on player or NPCs.

    The Hotspot component is necessary to make an NPC interactive - which is what the quote you referred to was talking about. If you aren't making the NPC clickable, and has no need for a Hotspot, you can ignore it.

    I run the scene according to the tutorial having only the prefab of Liam NPC visible.

    You appear to have instances of both your "Liam" and "Malcom" player prefabs present in the scene and disabled. Remove these from the scene, as they may be conflicting with the operation.

    Malcolm's Player Inspector screenshot is cropped - I'm assuming his "Associated NPC" is set to "Malcolm NPC". Temporarily also remove non-AC components such as the NavMesh Agent and Character Controller, so that we can rule out those contributing.

    Also be aware that the NavMesh Agent component requires the additional NavMesh Agent Integration component to work with AC properly.

    If there's no difference with the above changes, I'll need to see a unitypackage of this myself - again the Managers, also all 4 character prefabs, the test scene and the UI canvas prefabs / Menu ActionLists.

  • @ChrisIceBox I did all that you said. This are looking better but we are not there yet!

    *yes the cropped part is set to Malcolm NPC.

    Upon start I get both main player and the NPC (liam) at their correct positions.
    I then move main player to a spot.
    I then press switch player and then I get a message that the NPC (liam) was moved out of the way of the Player (liam) who has now become the main player (so I guess this is correct ).

    Then the previous player that has become an NPC (Malcolm) is moved to another spot (not the one I had left him when I've switched to Liam).

    Also I get a warning > Failed to create agent because it is not close enough to the NavMesh

    ( I have put to all players and NPCs the Nav Mesh Agent Integration script - by the way this is not in any tutorials )

    Then I press again switch and I get a message that Malcolm NPC was moved out of the way of the player Malcolm.

    After that moment pressing switch players changes them correctly and at the correct positions!

  • edited July 2019

    I have put to all players and NPCs the Nav Mesh Agent Integration script - by the way this is not in any tutorials

    AC characters do not require Agents to move, but the integration script is covered in the "Recreating Unity's adventure game" tutorial, as well as the Manual's "Unity Navigation pathfinding" and "Custom motion controllers" chapters. I shall, however, add a Warning message to the Console if one isn't added.

    Again, please temporarily remove the NavMesh Agent and NavMesh Agent Integration components. That will tell us if they are contributing to the problem.

  • Disabling NavMesh Agent and NavMesh Agent Integration components on both the players and their NPCs solves it. The change correctly and at the correct locations from the first time. I don't really understand why it works without these cause I thought these were necessary.

  • AC has its own navigation system - the use of the NavMesh Agent is optional, though also requires the NavMesh Agent Integration component.

    I've found that there is a positioning issue when switching players if the old Player's replacement NPC has a Character Controller. This, too, is optional - but a fix will be introduced in the next update.

  • So @ChrisIceBox what do you recommend to do.

  • edited July 2019

    Whether you use a NavMesh Agent or not is up to you - but it's not necessary.

    To fix the Character Controller issue in the meantime, open up ActionPlayerSwitch.cs and replace the line:

    newPlayer.transform.position = oldPlayerPosition;
    

    with:

    newPlayer.Teleport (oldPlayerPosition);
    
  • edited July 2019

    Hi @ChrisIceBox

    newPlayer.transform.position = oldPlayerPosition;

    this does not exist in the ActionPlayerSwitch.cs I think that you have done the change already cause i have found

    newPlayer.Teleport (oldPlayerPosition);

    in the script line 237

  • My mistake. Replace:

    runtimeOldPlayerNPC.transform.position = oldPlayerPosition;
    

    with:

    runtimeOldPlayerNPC.Teleport (oldPlayerPosition);
    
  • @ChrisIceBox oh so YOU DO make mistakes! :) Just joking you are great!

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.