• 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
Question by dohmee44 · Mar 06, 2012 at 11:29 PM · gameobjectinstantiatenameassignfor loop

Assign Names Problem

Hello , am having a really wiered problem with assiging names to prefabs am instantiating in the scene , each level I instantiate a number of objects in the scene and I specify a name for each , just using a for loop and adding i to the name of the objects, here is the code:

 var to_load:Number; // 3
 for(var i:uint ; i < to_load ; i++){
         Instantiate (ball, Vector3(Random.Range(-3, 3), Random.Range(-3, 3), Random.Range(2, 8)), Quaternion.identity);
         ball.name = "ball"+i;
     }

everything is working perfectly except that if I change the variable to_load in the inspector and I play the game , it loads objects an skip somehow a number which causes to have an object without the correct name, but if I reload the level "without any modifications , just click stop then play again" it loads the objects as its suposed to , here are 2 screenshots to explain better:

This is First time load: alt text

Second time load : alt text

I tried many methods ,also to avoide the inspector but with no results , anyone has an Idea what could be causing this problem ? thank you

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Kleptomaniac · Mar 07, 2012 at 08:13 AM

I'm not particularly sure what you're issue is (never used units before), however i changed some variables around and I believe this works. I basically got rid of your uint and instead declared to_load as an int:

 var to_load: int = 3;
 
     for(i = 0; i <= to_load ; i++){
         Instantiate (ball, Vector3(Random.Range(-3, 3), Random.Range(-3, 3), Random.Range(2, 8)), Quaternion.identity);
         ball.name = "ball" + i;
     }

Hope that helps! Klep

Comment

People who like this

0 Show 2 · 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 dohmee44 · Mar 07, 2012 at 08:16 AM 0
Share

hey , that does not really work for what am trying to do , but yes i fixed it just by assiging the name before instatiating , the problem might be that i come from a flash AS3 programming and it seems that unity has a diffrent way to assign names to the objects .

avatar image Kleptomaniac · Mar 07, 2012 at 08:18 AM 0
Share

Haha, glad you got it working in the end! Sorry I couldn't be of more help!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create a clone of an object with a different name 1 Answer

Instantiating gameObejcts that can't be referred to after creation 1 Answer

Instantiate only one Prefab per 40 unit 2 Answers

All subsequent instantiated objects = auto-named with suffix (Clone)? 1 Answer

Instantiate and then assign? 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