Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 James Ser · May 05, 2010 at 02:01 PM · prefabsarraysnameunique

generating unique names for prefabs within an array

Hi there,

I'm currently having some trouble creating unique names for my prefabs.

I have instantiated all my prefabs within an array.

Below is the code that I have used to Instantiate my prefabs.

I'm trying to build a scene using different types of tiles.

So what your seeing are a combination of neutral tiles and tiles that have arrows on them.

for (var j: int = 0; j < tileArrayList[i].Count; j++){

         if (tileArrayList[i][j] == 0) {
         //tile appears
             //Debug.Log("Start instantiating tiles");
             //newTile=Instantiate (tileEmpty,Vector3(tilePosX,0,tilePosZ), Quaternion(0,0,0,0));
             //newTile.name="TileEmpty";

         } else if (tileArrayList[i][j] == 1) {
             //tile appears
             newTile=Instantiate (tileNeutral,Vector3(tilePosX,0,tilePosZ), Quaternion(0,0,0,0));
             newTile.name="TileNeutral";

         } else if (tileArrayList[i][j] == 2 || tileArrayList[i][j] == 3 || tileArrayList[i][j] == 4 || tileArrayList[i][j] == 5 ) {

             newTile=Instantiate (tileSingle,Vector3(tilePosX,0,tilePosZ), Quaternion(0,0,0,0));

             if(tileArrayList[i][j] == 2){

                 newTile.name="TileSingleUp";

             }else if(tileArrayList[i][j] == 3){

                 newTile.name="TileSingleDown";
                 newTile.transform.eulerAngles.y-=90;

             }else if(tileArrayList[i][j] == 4){

                 newTile.name="TileSingleLeft";
                 newTile.transform.eulerAngles.y-=180;

             }else if(tileArrayList[i][j] == 5){

                 newTile.name="TileSingleRight";
                 newTile.transform.eulerAngles.y-=270;

             }

         }

Below is how the tiles are layed out after previewing in the game mode

Array Image Preview

What will happen here is that our robot will walk on to the tile that is pointing to the right and the tile will move to the right.

Now the problem that we're encountering here is that if we walk on the next arrowed tile, the first arrowed tile will still continue to move and that isn't what I want.

There is a post here in answer unity3d that has a similar problem http://answers.unity3d.com/questions/8885/affecting-only-one-prefab-in-code-script

and the solution was to use something called GenerateUniquename();

but I can't seem to find any reference on this term.

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
2

Answer by Ray-Pendergraph · May 05, 2010 at 02:34 PM

As a general rule, you can always use System.Guid (MSDN documentation) and append your names with a unique value using the Guid's ToString() method. I use this a lot when I need to uniquely identify resources at run time. These will not be very human readable.

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 Ray-Pendergraph · May 05, 2010 at 03:48 PM 0
Share

Let me clarify: newTile.name = "TileSingleRight_" + System.Guid.NewGuid().ToString();

They will definitely be unique. Of course if you wanted to somehow systematically reference them with the name, then $$anonymous$$olix's answer might be better.

avatar image Cyclops · May 05, 2010 at 03:59 PM 0
Share

@Ray, you can make the URL a link by using the world button. Also, it's not quite guaranteed, but close: "The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low."

avatar image Ray-Pendergraph · May 05, 2010 at 05:42 PM 0
Share

@Cyclops, fixed the link... thanks.

avatar image
0

Answer by Molix · May 05, 2010 at 03:42 PM

I don't think the function mentioned in that other answer actually exists--I think it was just meant as an example. If you just want unique names, you could just append the index you're using, e.g.

newTile.name = "TileSingleRight_" + i + "_" + j;

It may even help when you're debugging.

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

No one has followed this question yet.

Related Questions

Textmesh Username for networkplayers. help. 1 Answer

Naming array elements 1 Answer

Drag and Drop onto Array of Custom Objects 0 Answers

Trouble instantiating an Array of Prefabs 1 Answer

Generating a tiled world with roads, possibly using a 2D array? (C#) 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