Ok, so here’s the problem:
I have an empty persistent. I load level A into it ( with no transform ), and I want to load level B in a certain position, ie, with a transform so that it fits. I don’t just want them loaded on top of each other.
So, I put a marker in level A, where I want level B to load. And I put a marker in level B, where I want level A to load. I need both markers, because I want to be able to load B into, or A into B ( depending on how the game goes ).
The marker BP is very simple. I just need to know where, and what rotation ( I only do Z rotation, although all 3 axis is possible )
You don’t need anything in the marker. But I have some text, so I can see what’s going on. And I have a collision volume, so that if someone tries to cross into level B, but it’s not ready, I can stop the player until it is.
Like I say, I will have the corresponding marker in level B, where I want A to load.
Now… I already have the math implied here. Because I have already specified a certain position and rotation that I want B loaded at. And I know the marker in B says where I want A. So, how do I turn that into some math that will give me the correct transform for level loading? That’s where the loader BP comes in.
I have the text again ( just for info ), and a collision volume. When the player overlaps here ( or when I press the button in the editor ) it will load B into A ( well, the persistent, but connected to A ). The only runtime code is
I’m saying, when the player overlaps, I load level B with this transform info. There are a few more layers, bear with me…
Why use the game instance? Because it persists between levels, so I can keep track of which levels are loaded, so I don’t load them twice, and can unload them when need be. You can see, I’m passing 3 things here
- A reference to the load point in this level
- The location and rotation of the load point in level B ( you have to give this info to the load BP, I have a bit of code to pass it through the save game in editor, but you can just copy/paste it )
I do the translation between levels in a function before I pass the info to the GI
That is the critical bit of maths.
The rest of the code in the loader BP is only to help me during edit, to load/unload other levels
Nearly there Here’s what I have in the GI
I’m just checking if the level is loaded already. If not, I put it in the list and load it. Unloading is more simple
I think that’s everything. Read it a few times, and tell me how it goes…