Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Triqy · Dec 07, 2013 at 01:34 AM · objectsclonename

Is a clone object still a (clone) if you change the name of it using script?

Is a clone object still a (clone) if you change the name of it using script? I want to create 5 enemies but they all have to have different names. I have one script that will act as the enemies AI. Will the objects/enemies that I create act as Individual objects/Enemies or act as One. I Really hope this makes since... lol Thanks guys!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by clunk47 · Dec 07, 2013 at 01:41 AM

Each object has its own Instance ID and will not lose any kind of control or property by changing its name. For example if you want to Instantiate 5 prefabs or create 5 new GameObjects and name them according to their index in the array:

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour 
 {
     GameObject[] cubes;
 
     void Start()
     {
         cubes = new GameObject[5];
         for(int i = 0; i < cubes.Length; i++)
         {
             cubes[i] = GameObject.CreatePrimitive(PrimitiveType.Cube);
             cubes[i].name = "Cube" + i.ToString();
         }
 
         foreach (GameObject cube in cubes)
             print (cube.name);
     }
 }
 
Comment
Add comment · Show 7 · 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 Triqy · Dec 07, 2013 at 02:01 AM 0
Share

What I want to do is pool the enemies above the camera and then introduce the created enemies to the player at specific times during Gameplay by moving one specific enemy Jet by name.

I have the pooling done, but for some reason it is not finding the player in the enemy's AI script like it is suppose to do upon instantiating on start at the pooling site.

Also Should i force the created enemies in a new array and track them like that or should i just find each one by its name?

avatar image Triqy · Dec 07, 2013 at 02:05 AM 0
Share

Another question is what does .ToString(); do?

avatar image clunk47 · Dec 07, 2013 at 02:31 AM 0
Share

You can find them by name or index in the array.

By name:

 foreach(GameObject cube in cubes)
 {
     if(cube.name == "whatever name")
     {
         //DoSomething
     }

 }

By index:

 cubes[1]

$$anonymous$$eep in $$anonymous$$d indexes start with 0.

/////////////

As far as it not finding the player in the enemy ai script, i'd need to see the enemy ai script...

ToString() changes a value to a string. A GameObject's name property is a string, so you can't just name it "cube" + i, because i is an int. So if i is 1, i.ToString() would be "1" as a string. "Cube" + i.ToString() would be "Cube1".

avatar image Triqy · Dec 07, 2013 at 03:23 AM 0
Share

Ok with a little tinkering I got the findtag && the LookAt working properly on Instantiate of all 5 enemies in the AI Script.

I think i am going to use the array but i need to force the object now into that array. I have another script that finds all objects in the scene with ObjectsOfTType and it searches through that. Is it possible to search by partial name? example; Jet_0, Search the entire scene for objects that name starts with Jet?

avatar image clunk47 · Dec 07, 2013 at 03:31 AM 0
Share
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Example : $$anonymous$$onoBehaviour 
 {
     List<GameObject> jets = new List<GameObject>();
 
     void Start()
     {
         foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject))) 
         {
             if(go.name.StartsWith("Jet"))
                 jets.Add(go);
         }
 
         foreach (GameObject jet in jets)
                         print (jet.name);
     }
 }


Look at String.StartsWith for more info.

Show more comments

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

17 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

Related Questions

trouble adding script to clone object 1 Answer

child names of clone dont match model 1 Answer

getting the object that the running script is attached to 1 Answer

Different actions with same script called on differend objects 2 Answers

Why does one script not work on multiple gameobjects? 3 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