Load procedural level when player near world bounds

Hey all,

I’m trying to build a 2D game where the world essentially loops around on itself – where if the player goes past the top of the level, they actually continue at the bottom. I’ve read a bunch of different threads on here to figure what my options are, and the solution I’m currently working on uses world composition to swap levels depending on the player’s location.

I have two levels at game start: a parent “Universe” level, and a child “ProceduralSystem” level. The world’s geometry and contents are generated procedurally at runtime, so the levels are entirely empty at first – just a PlayerStart actor and a LevelBounds instance. The Universe blueprint is intended to contain logic for bounds checks and level streaming, and the ProceduralSystem level contains the actual geometry.

I’m struggling with bounds detection and dynamic level loading. What I’d like to do is, when the player character is half a screen away from the top of the world bounds, load a new ProceduralSystem instance positioned above the current one and let them seamlessly move between them – and then when the user is far enough into the new level, unload the old ProceduralSystem instance. Same goes for the other edges of the map, i.e. loading levels to the sides or diagonally as necessary.

I have two main questions:

  1. What’s the best way to calculate world bounds & player character proximity? I’m generating geometry between -100,000 and 100,000 (at various depths) and am just referencing the variable that tracks this, but I figure it might be smarter to use the LevelBounds object instead somehow. I just can’t seem to find a convenient way to get min/max bounds from it.
  2. I think my math for figuring out if the user is close to the game bounds is wrong. I’m trying to add half the viewport height to the pawn’s position, then compare it to the -100,000 limit, but it looks like viewport coordinates don’t map well to world coordinates. What’s the best way to figure out if the pawn is half-a-screen away from a given location?

I might just be thinking about this wrong so I’m open to alternatives as well.

Thanks.

Not sure if there’s a rule against bumping topics, but I’m still pretty stuck here and would appreciate some feedback.