Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 SolidusSnake · Aug 10, 2017 at 06:52 PM · scripting problemoptimizationprefabsprefab-instancememory usage

Unity loading prefabs difficulties. optimization

Hopefully anyone can help me out. I have a some different prefabs and a script which spawn those objects. I has created an array of prefabs and manually placed them there. But after some time the amount of prefabs increased. What if I had a more objects (100-200) ? How I have to find a right prefab and spawn it ? Public array of gameobjects in script will not be correct in this case (100 prefabs or more) ? What I have to do with this all objects? AssetBundles or Resource folder, which one will be correct ?

Comment
Add comment · Show 1
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 OusedGames · Aug 14, 2017 at 11:37 PM 0
Share

Hello buddy,
If you are a beginner just create your prefab Array, play your game and be happy...
But if not Resources is a good practice, but no need to worry if the game is running smooth, you can use the profiler to truly know your game performance issues

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kskjadav007 · Apr 06, 2018 at 10:05 AM

Objectpooling is best i think

public List m_pooledBullet;

 public int m_PoolAmount;
 
     void Start()
     {
         for(int i = 0 ; i<m_PoolAmount;i++)
         {
             GameObject obj = (GameObject)Instantiate(m_Bullet);
             obj.SetActive(false);
             m_pooledBullet.Add(obj);
         }
     }
 
     public GameObject GetPooledBullet()
     {
         for(int i = 0 ; i<m_pooledBullet.Count;i++)
         {
             if(!m_pooledBullet[i].activeInHierarchy)
             {
                 return m_pooledBullet[i];    
             }
 
         }
         return null;
     }
 
 
 
     void Shoot()
     {
         GameObject obb = GetPooledBullet();
 
         if(obb != null)
         {
             obb.transform.position = transform.position;
             obb.transform.rotation = Quaternion.identity;
             obb.gameObject.SetActive(true);
         }
         else
         {
             //Debug.Log("null");
         }
     }
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

116 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

Related Questions

Serialize script fields of prefabs with other prefabs, so that when I drag them into hierarchy, the connection becomes between game objects? 1 Answer

Unity 2D Game Issue: Script is only affecting one prefab instead of all of them. 0 Answers

How can I save multiple instances of a single prefab? 1 Answer

Are sprites reference (script) loaded every time? 0 Answers

Persisting Prefabs across scenes 1 Answer


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