Forum rules - please read before posting.

Problem with restoring player position after scene change

Hello!
I know this has already been covered on the forum,
but unfortunately I couldn't get it to work so far.

A short description of what I try to do:
The player is in a room where he uses an inventory item like a phone or minigame gadget, which triggers a scene change to a scene in which the player is not visible.
Before the scene switch I want to have the current player position recorded to a Vector3 variable with the Object - Record Transform action, in order to return to the exact position from where the item was accessed, when switching back to the original scene.
The original scene has an variable check on start, if it was entered through the gadget scene. This is set up properly, as I checked with further test actions.
But I tried with various settings of the Object - Transform and Object - Teleport actions to restore the player position at this point, but it always returns at the original PlayerStart2D marker.

Here is a screenshot of the action settings in question and of the Vector3 variable:


With the Object - Transform I tried both "translate to" and "translate by" position.
And I also tried with a "Remember Transform" component attached to the player prefab.
Probably something is wrong with the setup for my Vector3 variable?
I would be very thankful for any help.

Comments

  • Is the variable's value actually being set correctly?  You can see it's realtime value in the Variables Manager when the game is running.

    The Object: Teleport Action would be the better of the two Action types you've shown to re-apply it back to the Player - but you haven't defined a Marker.  The "Position relative to" Vector3 adds itself to the position of the Marker, but this Marker must exist.  Try assigning one placed at the origin (i.e. with a position of 0,0,0) so that the relative position becomes absolute.

    It's not clear if the Action is not running, or if it's not having an effect.  Try manually running this Action once the scene has finished loading by clicking Run now in the ActionLists's Inspector.

    Though this approach should work, I'd recommend you instead rely on player-switching to avoid having to restore the player's position.

    See the Manual's "Player switching" chapter.  You can create a new Player just for the minigame scene, and then switch back to the "regular" player afterwards - which will automatically restore their position.
  • Thank you very much, Chris!
    I am pretty sure now it had something to do with the Vector3 variable. I tried running the restore action manually and nothing happened when I used Object Transpose, but Object Teleport transported the player to this initial 0,0,0 marker.

    It's cool for now, as I solved the issue with the player-switching method, which is a very great approach!

    Unfortunately since this change, I have a problem with the music changing in these scenes. It seems this has to do with that the opening cutscene of the minigame scene is not run correctly sometimes.
    I have a Play Music action on start there (the music from the other scene fades out before scene switch). This music plays when the player first uses the gadget, but not the second time, though it is the same action list. A "New Game" button in the minigame reloads the scene and with this, the music always starts and resumes correctly.

    After I went back to not allowing player-switching, everything was cool again with any music/cutscene action.

    I know this would rather be cool as a new thread, but I thought I mention it here first, as it definitely must be connected with the player-switching in my case.
    I used Switch Scene, not add or remove and replaced the players when switching them.
  • When you switch to a Player for the first time in a new scene, that scene will run its OnStart cutscene.  When you switch to a previously-used Player (and are reloading that Player's data) it'll run the OnLoad cutscene instead.

    If the issue is what I suspect it is, you can solve it either by having both your OnStart and OnLoad share the same Actions, or uncheck Restore position? in your Player: Switch Action.
  • I made a short break with the scene and revisited it again.
    It was because of the OnStart cutscene thing and had not really to do with the music manager. 
    In the end it worked out fine.
    Thanks again!
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.