Hello, I want to make a small script that a user can type a number (between 1 to 10 million) and click on a button and then he will be moved into a first person game and in the game, the script will draw cubes on the screen, the amount of cubes will be the number the user wrote. Now this is a first person game so not all the cubes will be rendered at one but I still have a lot of questions… First of all, the first way I thought of going for this is just a for loop that creates a gameobject for each cube, but 10 million game objects? I thought of making 1 big model which contains a lot of cubes (I heard in unity there is a max of 65k vertices) and put that on but the problem is I want the player to have an option to change the cube’s distance from eachother.
How do you think is my best way to go about this?
Thank you very much
Don’t allocate 10 million objects. You need a way to abstract this. Maybe you could have 10 million elements in a table, but they shouldn’t be allotted GameObjects 1:1. Even better than 10 million elements would be some kind of area subdivision, such as an octree. For example, if the top half of your world is all blocks and the bottom is all empty, then your octree will only have 2 elements instead of 10 million.
Instantiate actual GameObjects only near the player. Use a pool for this, so you can reuse GameObjects instead of creating and destroying them.
I think I understood what you mean, please confirm that this is true: I need to divide my world into areas, and only make a small amount of cubes, and move these cubes to the area the player is in so it will look like there are everywhere he goes so it actually looks like there are 10 million cubes
Yes. I recommend two intermediate steps:
-
Make a very small world where you create all of the cubes. Get some basic gameplay working in this environment.
-
Read about octrees (see the link above) or some other area subdivision technique, and play with it in a few test scenes.
Then you can put both of these together to make what you described.
Ok, thank you very much