- Home /
Large Volume of Game Objects - is there another way?
I thought it would be fun to build a visual compound interest calculator in Unity. The goal is to allow kids to visualize the power of compound interest via the accumulation of $10,000 "straps" or "bands". It is a pretty simple concept; as the years progress, the pile of money gets larger. The code below works but generates a random pile of cubes (stand-in) for the money bands. This is generating thousands of game objects and is putting strain on the CPU. This will not work for my plan of running this visualization in mobile AR.
I'm new to Unity but I wonder if it would be best to group game objects and maybe forgo some of the physics calculations? A vertical stack of 20 or so wide would make for better visualization so maybe create game objects for the items on top and then extend the bottom rows vs. creating new game objects? Any ideas or suggestions would be appreciated.
Jeff
IEnumerator Loop()
{
instanceCount = accumulated / 10000; //get's 10K stacks!
yearAccumulated = instanceCount - iCounter; //designed to get the incremental value per year
yearAccumulated = (Mathf.Floor(yearAccumulated)); //Changed from Mathf.Round as this rounds up and I it to round down.
Debug.Log(yearAccumulated.ToString());
//Debug.Log(instanceCount.ToString());
for (int i = 0; i < yearAccumulated; i++)
{
Vector3 position = new Vector3(Random.Range(-3.0f, 3.0f), 3, Random.Range(-3.0f, 3.0f)); //creates stacks in random range
Instantiate(prefab, position, Quaternion.identity);
iCounter++; //increments loop counter
Debug.Log(iCounter.ToString());
yield return null;
}
}
Can't you just stretch a single cube? Perhaps a picture of desired result would be in place here
Answer by Strixie13 · Oct 24, 2019 at 04:59 PM
You would have to find a way to bring the object count down. Mobile is super limited so any solution would involve a small object count and minimal physics. Object count is medium-expensive, and physics calculations are super-expensive. Not too familiar with AR, but I think it is even more strenuous on the device for computation?
For your specific example I would have maybe 3 bands with full physics enabled, and then every time the number of bands gets to X large number, add model of a stack of cash (using a box model with a texture). Those could also have physics enabled, and since box colliers are pretty cheap you could have maybe 20-30 of them in the room? That gives you the ability to interact with the environment, you get the feeling that the room is full of stuff, and will not blow up your device :)
Thank you for the suggestion. I like the idea as I could scale the models exponentially along with the numbers. This should keep the game object count to a much more reasonable number.
Your answer
![](https://koobas.hobune.stream/wayback/20220612213845im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Create with code 2.2 pizza not shooting 1 Answer
How to tell at runtime if a GameObject is a prefab 3 Answers
how to get the prefab path of a game object in Game mode,not Editor mode 1 Answer
Prefab doesn't keep it's public variable when Instantiated? 2 Answers
Getting MouseEnter to Another Object 1 Answer