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
1
Question by Jordan Miller 2 · Apr 28, 2010 at 06:22 AM · stringfindsyntax-errorcallbce0017

GameObejct.Find using string variable for name

usually you'd type

gameObject.Find("someObject") 

to find that object, but in my game I'm using

gameObject.Find(string1)

where string one is the name of a game object. Like this:

string1 = "First Person Controller"; string2 = "FPSWalker";

gameObject.Find(string1).transform.GetComponent(string2).some Function();

however I get the following error:

Assets/Scripts/TerrainScript.js(34,48): BCE0017: The best overload for the method 'UnityEngine.GameObject.Find(String)' is not compatible with the argument list '(char)'.

it doesn't make any sense to me because I'm just replacing a string with a string variable, why does it not work?!

Comment
Add comment · Show 1
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 duck ♦♦ · Apr 28, 2010 at 07:09 AM 0
Share

It would probably help if you pasted the actual code you're using, not an example of what it's like.

1 Reply

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

Answer by duck · Apr 28, 2010 at 07:13 AM

Well, in the code you pasted, you have a lowercase g for gameObject when it should be GameObject, and you have a space in the "some Function()" name. Neither of these is likely to be your problem though.

It's most likely an error in some part of the code that you haven't pasted.

You'll convert a string to a 'char' if you use square bracket access on the string at some point, so I guess you're doing this by accident earlier in the script. Eg:

var myString = "foo";
var obj = GameObject.Find(myString[1]);  
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 Jordan Miller · Apr 28, 2010 at 06:26 PM 0
Share

I tried it with both a GameObject and lowercase gameObject and I get the same thing. Ah, you're right, I was making string1 = whodo[0] which I thought I had assigned to be an array but it was actually set as a string thus giving us the 'char' error! excellent work $$anonymous$$r. Duck!

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

NullReferenceException when transform.Find(string) STILL 1 Answer

String to Var 1 Answer

Variable from String 0 Answers

Access a GameObject through it's tag, using a string. 1 Answer

The best overload for the method 'UnityEngine.Object.FindObjectOfType(System.Type)' is not compatible with the argument list '(s_mainCharacter)'. 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