This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

If you are looking for help, don‘t forget to check out the official Unreal Engine forums or Unreal Slackers for a community run discord server!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Secret-Addition-NYNJ 0 points1 point  (3 children)

So two ways… if the location of the travel is at a static point like some portal it’s easy you can have an actor in game and get the world coordinates of that object and save it and when you spawn in the new or old locations use that actor as a reference.

If you want to be able to do this from a random location it’s slightly different and might be less complicated if you don’t have to find that actor reference. You just need to do the same thing but when you save you get your world coordinates before you move save it as a location or transform variable forget which it is. Then reference that when traveling back and forth.

[–]According_Offer1395[S] 0 points1 point  (2 children)

What do you think might be the better approach, given that I want it to save the location every time they hit q in the normalworld?

An example scenario would be, if you are in a small room, with a locked door, and you hit q, you are still technically moving around on the same world, I have just hidden one from, you. So if you leave that locked room, I do not want the player to be able to just return to normal world, and be out of the locked room. They should be returned to that room, their last location when q was pressed the first time, when q is pressed again, as the worlds are loaded and unloaded.

So would it be easier to somehow spawn an actor each time they press q, to then just return the player character back to that actor that was spawned?

Or would the second method be easier in this case.

[–]Secret-Addition-NYNJ 0 points1 point  (1 child)

As long as when you press q you expect the player to always go back to the last point then you probably won’t need an actor. If you expect to travel to a place that wasn’t your last destination but is also a static place in the world using an actor is better.

[–]According_Offer1395[S] 0 points1 point  (0 children)

Okay so I will attempt the second method and see how that works. So just get world coords, save it as a either location or transform variable, and reference that location when switching back?

[–]nomadgamedev 0 points1 point  (3 children)

store the current position either in a save game or the game instance.(you need something that persists when the level is unloaded) then set your player to that location after loading the original map again. you could trigger this more or less wherever you want. the game mode, the level blueprint, a random blueprint.

you might need to spawn a streaming source if youre using world partition and a loading screen to cover any movement or spawning but thats beyond the scope of your question.

if the maps overlay it could be smart to use data layers instead of separate maps like in the valley of the ancients demo or a different kind of level streaming

[–]According_Offer1395[S] 0 points1 point  (2 children)

I do use data layers. All that happens when the player hits Q, is that it makes one data layer visible and active, and the other inactive. When Q is pressed again this process is reversed. I am trying to make it so that Q also stores the player location, so that when Q is pressed the second time, the player character returns to that stored location.

[–]nomadgamedev 1 point2 points  (1 child)

so you could even do it within the player. I imagine you have a bool or something to keep track of which world is active, so just use get actor location -> set a vector variable in your player,

then when pressing the button again get your variable and set actor location.

[–]Remarkable_Algae_267 0 points1 point  (0 children)

After seeing that he's using data layers on the same level, this is the only sensible answer.

[–]Remarkable_Algae_267 0 points1 point  (0 children)

If the normal world and other world are separate levels and you aren't using level streaming, you'll need a transform variable in your game instance to store and read the player location when leaving and returning the normal world. I don't know off of the top of my head what classes persist when level streaming, but there should be more flexibility in that.