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 /
  • Help Room /
avatar image
0
Question by awplays49 · Sep 25, 2015 at 05:46 PM · instantiateplaneplanes

Have to instantiate a 9x9 of planes and its slow. What can I do to fix this?

I have a good desktop that can handle a lot, but it takes about 3 seconds to load 81 planes. How can I fix this?

Comment
Add comment · Show 2
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 Dave-Carlile · Sep 25, 2015 at 05:55 PM 0
Share

This is missing a lot of information. You say "instantiate" in the title, but "load" in the problem description. Those are substantially different concepts. Include some code and narrow down the problem for us.

avatar image awplays49 · Sep 25, 2015 at 06:53 PM 0
Share

@Dave Carlile this is executed by a simple custom editor.

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$apGenerator : $$anonymous$$onoBehaviour {
     
     public GameObject tile;
     public GameObject floor;
     public int mapSizeX, mapSizeY;
     [Range (0, 100)]
     public int tileOutlinePercentage;
     
     public void Generate$$anonymous$$ap () {
         if (transform.FindChild ("$$anonymous$$ap"))
         {
             DestroyImmediate (transform.FindChild ("$$anonymous$$ap").gameObject);
         }
         GameObject map = new GameObject ("$$anonymous$$ap");
         map.transform.parent = transform;
         GameObject mainTile = Instantiate (floor, Vector3.zero, Quaternion.Euler (90, 0, 0)) as GameObject;
         mainTile.transform.localScale = new Vector3 (mapSizeX, mapSizeY, 0);
         mainTile.transform.parent = map.transform;
         for (int x = 0; x < mapSizeX; x ++)
         {
             for (int y = 0; y < mapSizeY; y ++)
             {
                 float mapHalfX = mapSizeX;
                 mapHalfX /= 2;
                 float mapHalfY = mapSizeY;
                 mapHalfY /= 2;
                 Vector3 tilePos = new Vector3 (x - mapHalfX + 0.5f, 0.01f, y - mapHalfY + 0.5f);
                 GameObject newTile = Instantiate (tile, tilePos, Quaternion.Euler (90, 0, 0)) as GameObject;
                 newTile.transform.localScale -= Vector3.one * tileOutlinePercentage / 100;
                 newTile.transform.parent = map.transform;
             }
         }
     }
 }
 



1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GimLee · Sep 25, 2015 at 07:11 PM

Instantiating and destroying comes with relatively high cost. It is better to instantiate your Map in the Awake() function, and disabling all their renderers, so they are invisible.

When you need them, you can do a foreach to enable the renderers again.

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

30 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

Related Questions

Instantiate based on distance 1 Answer

How can i Instantiate gameobject in array 0 Answers

When I Instansiate a gameobject as a children the parent duplicates. Why? 1 Answer

Order of initializing (networked) objects 0 Answers

[Asset Bundle] Split the prefabs into a single gameobject 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