• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Cletus2000 · Jun 02 at 02:06 AM · instantiateoptimizationgameobjectsmultiplebatching

Batching objects with Instantiate for optimization

Hello, i was trying to instantiate many objects in random positions, but my frame rate didnt seem to like that, so i´ve been trying to optimize it for hours now. I discovered that batching should work, because every object is really the same one, but i can´t get it to work. Here is my code:

     public GameObject candle;
     public int initialSpawn;
 
     [Min(0.0001f)]
     public float velocity;
     public float radius=60;
 
     void Start()
     {
         GameObject[] spawnedCandle = new GameObject[initialSpawn];
         for(int i=0; i< initialSpawn; i++)
         {
             //Sets a random point around this spawner object
             gameObject.transform.Rotate(new Vector3(0, Random.Range(0f, 360f), 0));
             //Creates a candle in that random point
             spawnedCandle[i] = Instantiate(candle, transform.position + transform.forward * Random.Range(0f, radius), Quaternion.identity);
             spawnedCandle[i].transform.Rotate(new Vector3(90, 0, 0));
         }
         for (int i = 0; i < initialSpawn; i++)
             {spawnedCandle[i].transform.parent = transform;}
         
         StaticBatchingUtility.Combine(spawnedCandle, candle);
     }


I dont know if i should use another object as the parent in the StaticBatchingUtility.Combine() function, or im doing something wrong, but draw calls kepp getting to high numbers, instead of just a couple for each different element.

I´m also posting a photo of the result just in case it helps. alt text

I also tried simplyfing the candle object to simply a bowl, wich is 1 mesh and of course 1 material, but still high draw calls.

captura-de-pantalla-2022-06-02-040303.jpg (313.9 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rh_galaxy · Jun 03 at 04:21 AM

I haven't used StaticBatchingUtility.Combine() and am not sure what time it saves, but doing all the Instantiate in Start() makes it all happen in one frame... try spreading it out to be done in Update() incrementally.

Like Instantiating 50 candles each frame and see what happens...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Cletus2000 · Jun 03 at 01:09 PM

I give up, i´ll just spawn the ones nearest to the camera and fake the further ones with particles. I´ll stay with the 3600 batches and 200fps, instead of 38 and 500fps, because its fine for this scene, but in case of wanting to take it further and put gameplay on it, it would probably be hell. I wish someone would come up with a system of prefabs acting as particles.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Optimize Having Thousands of GameObjects 0 Answers

How to force static batching being performed at runtime? 0 Answers

How to Spawn multiple game object one by one in random order 1 Answer

Need optimizing tips for mobile third person shooting game. 2 Answers

Batching runtime instanced Objects 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges