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 Novitch · Aug 16, 2013 at 04:45 AM · objectstring

Implicit downcast from 'Object' to 'String'.

 Any idea beside #pragma downcast?

   
  
 
 private var stateArray = new Array [3];
 private var replyArray = new Array [3];
 
 private var controlCenter : GameObject; 
 var state : int; 
 
 
 
 function Start () {
 
     
    controlCenter = gameObject.Find("Control Center"); 
 
      
    stateArray[0] = lookupState0;
    stateArray[1] = lookupState1;
    stateArray[2] = lookupState2;
    
     
    replyArray[0] = repliesState0;
    replyArray[1] = repliesState1;
    replyArray[2] = repliesState2;
 
 }
 
 
 function LookUpState (object : GameObject, currentState: int, picker : String) {
 
     var element : int = 0; // variable to track the element number for a match 
 
     if (picker == controlCenter.GetComponent(GameManager).defaultCursor.name )    var matchCursor = "default";
     else matchCursor = picker;
 
    for(var contents : String in stateArray[currentState]) {   //***** error here - Implicit downcast from 'Object' to 'String'
 
    
    var readString : String[] = contents.Split(",".Chars[0]); 
 
 
    if(readString[0] == matchCursor) {
             
             var actionMsg : String = replyArray[currentState][element];   //***** error here - Implicit downcast from 'Object' to 'String'
             controlCenter.GetComponent(GameManager).actionMsg= actionMsg;
             TimeAdjuster(actionMsg); 
 
              var nextState : int = parseInt(readString [1]);  
              object.SendMessage("ProcessObject", nextState); 
 
             var tempLength = (readString.length); 
 
             if(tempLength > 2){ 
                 for (var x = 2; x < tempLength; x = x + 2) { 
             
             var tempS = readString[x];
                 if (tempS.Substring(0,1) == " ") tempS = tempS.Substring(1);
 
             var auxObject = gameObject.Find(tempS); 
             var newState = parseInt(readString[x+1]);
             
             auxObject.SendMessage( "ProcessObject",newState);
 
         } 
        } 
      } 
      
     
     
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 clunk47 · Aug 16, 2013 at 04:48 AM 1
Share

You need to post the full script. If this IS your full script, you have a ton of undefined variables. You also need to be WAY more SPECIFIC! Describe your issue, where the issue is in the code, why you want to change it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Graham-Dunnett · Aug 16, 2013 at 02:34 PM

'stateArray' is un-typed, so Unity assumes it is an array of Objects. Your line 39 grabs one of the Objects and says it's a String, which the compiler correctly tells you is an implicit downcast. You probably want to use #pragma strict (which all scripts have out of the box) to help remind you to type your objects correctly.

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

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

Parse string object from SmartFoxServer 1 Answer

Object reference not set... but... it is? 0 Answers

Create a Custom Vector3 Object 2 Answers

Unity 2018.2.0f2 Crashing to Desktop with "Object is already loaded" errors. 2 Answers

Can't add Transform to an Array on Prefab. 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