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
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.
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.
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.