Hi,
So I've been working on a procedurally generated world. I've got the chunk system working fine. It loads in 3x3 chunks, each chunk a tilemap, with the player at the center. So if you move upward, the bottom row (of three chunks) is deleted and three new ones are created above the player as a new row. The tile maps place tiles according to a few fast noise maps.
My next step was to add "objects" like trees, caves, etc. Every time a chunk loads, it checks if the chunk has been loaded before, if not, it generates caves which are all Area2D's, and they are placed in random locations. If the chunk has been loaded before, it loads in the caves but with their previously assigned locations that I've stored in a matrix. So in new chunks, once they are assigned locations, that Vector2 of their (x, y) positions are stored in the matrix. Therefore the matrix is 2D, where the first index gives a chunk ID, and the second index gives coordinates for a cave in that specific chunk.
So it would be like this...Matrix =[ [(2, 3), (5, 8)], [(8, 7)] ]
Where two caves at (2, 3), (5, 8) are in chunk 0. And one cave (8, 7) in chunk 1.
The caves are created at the same time as the tiles are built for the tile map. So within an if a function like "if biome == grass" place a grass block and also creates a cave a percent of the time.
This is all fine and good, but then I want to delete the caves, I could not find a way to specify which instances I wanted to delete, so instead I made the caves nested inside the tilemap node for the chunk they are in. So when that chunk gets deleted, the caves are automatically gone with it, which works great.
But I've run into an issue with trying to get Ysort to work. I want the player and the cave to be ysorted so that the player can move around the cave. But the player and the instanced caves are not within the tree in a way that I could use the y sort property.
I put the player and the original cave in a Node2D to test ysort, and it works for them obviously. But the instance caves are within their respective tilenodes so it doesn't for them.
So I'm not sure how to solve this. Any help would be greatly appreciated.