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 frmusta · Jul 01, 2010 at 11:12 PM · gameobjectarraystringconvertbce0022

Convert String to GameObject[] type Array

I have found similar questions but they dont seem to answer my exact question.

What i am trying to do is set a newly created GameObject[] equal to a GameObject[] that has been filled before runtime manually while using a String to connect the names.

Here is what i mean,

var highlightsNight : GameObject[]; //this is filled manually in editor with what i need to highlight var timeOfDay : String = "Night"; //there can be more than one time of day, changes dynamically from a string comparison elsewhere

function turnOnHighlights() { var currentHighlights : GameObject[] = ("highlights"+timeOfDay); //need to set this by String name equal to the highlights for that time of day }

Thanks for your help! I hope this is an easy one, i just cant seem to get around the error involving Cant Convert String into GameObject.

EDIT, Sorry for the confusion. ----------------------------------------------------

I will try to make this more clear!

I have multiple GameObject[]'s declared inside of a script called waypoints. When you attach the waypoints script to something, an empty GameObject for example, you can then, in the editor manually define the length and add game objects by dragging and dropping them into this array list area created in the scripts component area on the GameObject that this is all happening on.

In this same script i also have to create an empty GameObject[] on the fly. Then set this new GameObject[] equal to one of the ones i previously declared and explained in the pervious paragraph. How can i tell the newly created GameObject[] to be equal to one of the perviously created ones by used of a string? When i try this it doesn't work.

var highlight_i2 : GameObject[]; // i will fill this up in the editor with objects i want to highlight during step i2 var thisStepName : String = "i2"; //this is a constaly changing string which i use to direct where we are in the scene

 function turnOnHighlights() //this gets called every step in the scene to change what is highlighting
 {
     var highlightObjects : GameObject[];
     highlightObjects = GameObject.Find("highlight_"+thisStepName); //This is what i cant figure out

// do you see what im trying to do here? //all of my highlight arrays are named "highlight_(stepName)" like the one above //goes on to highlight these objects in highlightObjects }

and i get the following Error:

Assets/Scripts/waypoints.js(318,51): BCE0022: Cannot convert 'UnityEngine.GameObject' to '(UnityEngine.GameObject)'.

Comment
Add comment · Show 3
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 Ricardo · Jul 01, 2010 at 11:42 PM 0
Share

Your question makes little sense, I'm afraid. The code you post attempts to concatenate a string with an array of gameObjects, something that the compiler will barf at. What exactly are you trying to accomplish? To simply change the name of each gameObject, or something like pre-filter the list of gameoObjects based on a tag or name pattern?

avatar image spinaljack · Jul 02, 2010 at 12:14 AM 0
Share

Do you want an array of strings? cos that's just String[]

avatar image frmusta · Jul 02, 2010 at 12:48 AM 0
Share

I edited my main post to help clarify, hope this helps.

2 Replies

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

Answer by _Petroz · Jul 01, 2010 at 11:49 PM

If you're trying to lookup a GameObject by name you should use GameObject.Find

http://unity3d.com/support/documentation/ScriptReference/GameObject.Find.html

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
avatar image
0

Answer by Tetrad · Jul 02, 2010 at 01:47 AM

There isn't a function to find all the game objects with a given name.

If you use tags, though, you can use GameObject.FindGameObjectsWithTag

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 Lucas Meijer 1 ♦♦ · Sep 11, 2010 at 08:47 PM 0
Share

There is: GameObject.Find()

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

convert GameObject to Rigidbody type 2 Answers

Array - Convert Object into Int 5 Answers

String Parsing 1 Answer

How to convert a string to int array in Unity C# 1 Answer

Converting String to a Game Object 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