Forum rules - please read before posting.

Character Switching Confusion

Apologies if this answer is out there, but what I found did not solve my problem, hence this post. Here's the scenario:
  • I have three player characters that players can switch between.
  • The two characters that are not being actively controlled should continue to exist where they were last left in the world.
  • I can successfully switch between characters using a make-shift on-screen UI button with a hotspot on it.
So here's my problem -- I can't find an effective way to get the Player I was just controlling to stay in the world at the spot I left them. There are two options for "Old Player" but neither of them seems to accomplish this goal:
  • "Remove from space" takes the old Player out but does not replace them with the NPC.
  • "Replace with NPC" only has specific options, but I do not know how to indicate what Player Character the player was just controlling.
Am I missing something with a custom UI setup based on what character the player is actively controlling, or something along those lines?

Comments

  • Welcome to the forum, @DHStom.

    A Player (as in prefab) cannot exist in the scene unless it is actually under the player's control, which is why the "Replace with NPC" option exists - essentially you'll want to swap your Player with an NPC that has the same graphics, so that it becomes interactive but is changed out without being apparent.

    You can use the Player: Check Action to determine which player is currently being controlled, and follow it up with different Player: Switch Actions (that each bring in a new NPC) accordingly.

    You'll actually want to have two Player: Check Actions, and three Player: Switch Actions, as you have three potential players that could be active.  Be sure to use the ActionList Editor window to make the logic flow more clear to understand.
  • Awesome, did not see the "Player: Check" action. That makes perfect sense. Thanks!
  • I know it has been a few weeks (I worked on a single character demo for awhile) but I am still having some issues here.

    So I have the logic working correctly. I switch to the correct character and an NPC switches in for the character I was just controlling.

    However, I cannot get the NPC that switches in to take the exact position that the character was at or facing. The NPCs also disappear when I'm in another scene and come back. I have both a "Remember NPC" and "Remember Transform" component on them, and I do have their prefabs in a "Resources" folder.

    I feel like I've gotten the hang of quite a bit of the Adventure Creator toolset, and have enjoyed using it. This process for dealing with multiple characters is currently the exception, unfortunately. I would personally be quite happy if this area of AC got some additional support in the future. Thanks!
  • I always investigate issues of which I am made aware.  I will look into your issues and will let you know if I need more information.
  • I cannot recreate any of the issues you are reporting.

    You do not need the Remember Transform component on your NPCs - the Remember NPC script will save their location, and as they should be present in the scene (though hidden until needed), they do not need to be instantiated and placed in a Resources folder.

    Also be sure to hide the relevant NPC before switching Player by using an Object: Teleport Action just before the Player: Switch to move the NPC to a far-away Marker.
  • Okay, I have it 80-85% of the way there. I did change up your order a little bit to do the Teleport after the switch so that the Player object would come in at the NPC's current location, and then the NPC would be teleported to an NPC Market outside the scene.

    My current problem is with switching scenes. Because this is used throughout my game, I've been using an ActionList Asset attached to my UI buttons for character switching. As such, I was hoping that a pre-fab NPC Marker could be attached to the ActionList Asset and then dropped into each scene.

    That does not seem to be working. Any time I am in a new scene, even if it has the pre-fab marker, the NPC does not teleport to it. It stays in the scene. Is there another way to do this that I am missing?
  • Create dedicated Marker prefabs for each NPC, so that you can re-use each for each scene.  When dealing with GameObjects in ActionList Assets, AC's Actions rely on ID numbers rather than prefab references.

    Take a Marker from your scene and drag it into the asset-based Object: Teleport Action's Marker field.  You'll see that it generates and displays a Constant ID number below.  Select the Marker, find the Constant ID component, check Retain in prefab?, then make it a new prefab (be careful not to overwrite the original AC Marker prefab).

    You can then use local copies of this same prefab in your other scenes.  Notice that when you drag it into a new scene, the Constant ID number is the same as it was in the other scene.  When the asset-based Action runs, it'll look for any object with that ID number - so it'll use that Marker regardless of which scene you're in.
  • I got it working! I had done most of what you said already, but I had not been using the pre-fab version of the marker in the Teleport script, instead just grabbing the local version of the pre-fab in the scene. (I don't know why that makes a difference. Perhaps it did not.)

    I also made a mistake by putting my NPC check in OnStart instead of OnLoad. (I wrote a script upon starting a scene to check what character you're using which moves the equivalent NPC to the marker.) One or both of those things did the trick!
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.