Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
1
Question by BigBulle · Mar 29, 2011 at 03:20 PM · editorinstantiate

Fastest way to instantiate and move multiple game objects in the editor

Hello everybody :)

I have a script editor that instantiate a large number of small objects in my scene, around 1000 units.

This takes a lot of time to complete (around 15 sedonds) which is not really a problem for the creation.

However this editor script allows me also to move (translation + rotation) all these objects at once and this operation takes almost the same time. This is quite annoying because I have to move these objects quite often while editing my scene.

Is there some way to improve these instantiation and moving actions?

Here is a snippet of my code:

List<GameObject> m_CurveObjects = new List<GameObject>();

// Draw abject along a curve while (position < curve.Length) { curveGameObject = (GameObject) Instantiate(CurveObject); curveGameObject.isStatic = true; m_CurveObjects.Add(curveGameOject); }

                 curveGameObject.transform.localPosition = newposition;
                 trackGameObject.transform.rotation = new Quaternion();
                 trackGameObject.transform.Rotate(myangle1, myAngle2, myAngle3);

                 position += SpaceBetweenObjects;

             }
             position -= segment.Length;
         }

When I only move the objects, I do the same things, but instead of instantiating I go through the list where I stored my objects.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Statement · Mar 29, 2011 at 03:30 PM

Are you sure you really need to instantiate 1000 GameObjects for that purpose?

It seems to me that you are making some sort of curve from several dummy objects (transforms) which would only slow your game down. It might be easier to just create a list of CurvePoints that isn't derived from MonoBehaviour and work on that set of objects instead. If you still want to be able to manipulate them through the editor, you could create an editor script that do this for you. Of course, I don't fully know what you intend to do with these GameObjects you're creating, but I thought it might still be worth mentioning. If you want to be able to store the list you need to add System.Serializable attribute to the class.

Comment
Add comment · Show 3 · 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 BigBulle · Mar 29, 2011 at 03:47 PM 0
Share

Thank you very much for your answer! Actually I tried to place many instances of objects along a road (e.g. signs, plants, lights, ...) I know the curve that follow this road so the code above simply walks along this road and places objects one by one by instantiating them. I must admit that I don't really understand the list of CurvePoints that you've mentioned above.

avatar image Statement · Mar 29, 2011 at 04:13 PM 0
Share

Well ins$$anonymous$$d of working with $$anonymous$$onoBehaviors you'd just work with naked classes. They are light weight and doesn't "exist in the scene", but they exist in your script. It would be too much of a lengthy discussion about this. An example class is found here: http://unity3d.com/support/documentation/ScriptReference/Serializable.html

avatar image BigBulle · Mar 29, 2011 at 08:51 PM 0
Share

Sorry, I still dont understand your comment and the relevance of the link. $$anonymous$$y curveObjects are GameObjects, not $$anonymous$$onoBehaviour. But maybe you're saying that GameObjects are too heavy and that I should work with lower level objects or maybe giving a list of location to a shader? (I also wanted to precise that I'm very used to C# and to the UNity's serialization->maybe this could help you to see what I don't understand)

avatar image
0

Answer by by0log1c · Mar 29, 2011 at 03:23 PM

Try adding a:

yield;

anywhere in the while(){} block. It should allow for a frame to go between each manipulation, making the total process longer, but restoring control ( aka: not freezing).

I think it could help.

Comment
Add comment · Show 1 · 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 BigBulle · Mar 29, 2011 at 03:48 PM 0
Share

Thank you for your quick answer! Actually I'm not annoyed by the freeze of the editor but by the actual time of the operation.

avatar image
0

Answer by loginpawan · Aug 16, 2012 at 02:11 PM

hello how can i control the animation applied on multiple gameobjects i used the script===== public var timer : float =0.0; var apple : GameObject; function Update(){ timer += Time.deltaTime; if(animation.IsPlaying("bounce")) { Debug.Log("Mellon is bouncing"+timer);

// apple.animation.Play("AppleBounce"); apple.animation.Stop("AppleBounce"); } // animation.Stop("AppleBounce"); if(timer>=3 && timer<6) { animation.Stop("bounce"); // Debug.Log("Mellon is bouncing"); apples(apple,"AppleBounce"); Debug.Log("function return in calling fn"+timer); // animation.Play("MelonBounce"); //timer=0.0;

} if(timer>=9 && timer<=12) { Debug.Log("comes in timer"+timer); apple.animation.Play("AppleBounce"); animation.Play("bounce"); Debug.Log("both are playing"+timer);
} }

function apples(apple:GameObject,animName:String) { apple.transform.animation.Play("AppleBounce"); Debug.Log("Apple is bouncing"+timer); if(timer>6 && timer< 9) { animation.Stop("AppleBounce"); //multiObject() } return; }

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

1 Person is following this question.

avatar image

Related Questions

Dynamically update the editor? 3 Answers

Can't open scripts with monodevelop? 1 Answer

AssetPreview.GetMiniTypeThumbnail not working for custom scripts 0 Answers

UniSciTE in version 3.x Script Edtior 1 Answer

Can I auto run a script when editor launches or a project finishes loading? 4 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