- Home /
Instantiate upward with layout group
I'm planning on making a list with a lot of images, like, a looot of images, but if I had too many loaded in all at once my software would lag the hell out. So I have a system whereby using collision I can detect where the camera is and spawn in more images below. Cool, now I can scroll down... but what about up? Instantiating prefabs into a layout group will automatically spawn them in below the rest of the layout group in order. So this way I'll have one of 2 problems.
1) I can scroll down and the software will continue loading images until the lag takes over and everything crashes.
2) I can scroll down and the software will load in new images but I can't scroll up, kind like the original super mario bros, only rotated 90 degrees.
As you can see these are both bad options and I don't know at all how to avoid them, please help, please, I'm begging you, I'm on my knees, please help me.
Answer by AlgoUnity · Sep 22, 2021 at 11:23 PM
I don't know anything about layout groups personally, but if you can't find a way to make it work you would want to basically make the system for listing your images yourself. Basically, the position of the images on the screen should be independent from their position in the collection, so you can keep adding and removing images from a List or Dictionary and it wouldn't affect other images' position on screen. Instead of your "base" image being the one at the top of the screen and listing down, your base image could be the one at the center of the screen and you expand both upwards and downwards every time, even at the start. When you move the scroll area, you change your base image to the one that is now at the center of the screen, and check that there are 10 images loaded above, and 10 below, and unload the ones that go further than that. Hope this helps, although I think there's a chance Unity already has something built in to do it for you so you may want to dig through the documentation more before going through all this code logic.