Trying to create a 2D platformer with two "dimension"

Godot Version

4.2

Question

I’m trying to create a 2D platformer where you can change dimension. Basically just two tilemaps on top of each other, where when you tap a button, it’ll show the other one, but keep the player position/momentum. The enemies and such will also be different from each dimension, and I’m also considering some different physics (like opposite gravity).

My question is, how do I change which tile map is seen? I can change the visibility, but the player still collides with it. I could have two scenes that I change between, but then the player position/momentum will be awkward, and anything that needs to be in both levels (like collectibles) would be troublesome - at least if it’s not the same in each level.

The best solution I can think of is changing the visibility of one node and going through the collision layer for each and every node inside it, at resetting it, but that seems like a lot of work for something fairly simple… I suppose it’s just a for each loop for all its children, but still, there must be a better way, right?

If the two dimensions use different collision layers, you only need to change the player’s collision layer/mask. Alternatively, you could remove the inactive tilemap from the scene tree and keep a reference to it, so you can add it back later. Keep in mind that if you have nodes outside of the scene tree, you have to free them manually to avoid memory leaks.