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
1
Question by YuyaOkada · Jul 16, 2014 at 12:40 PM · convertconverting

How to Convert System.Object into int ?

I want to convert Object into int.

 Object foo = 100;
 int bar = Int32.Parse(foo);

'>>InvalidCastException: Cannot cast from source type to destination type.

How should I do?

Thank you.

Comment
Add comment · Show 2
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 VesuvianPrime · Jul 17, 2014 at 10:35 AM 0
Share

Perhaps a better question is: why do you need to? A question like this suggests to me that there is an underlying problem with the architecture.

avatar image Kiwasi · Jul 17, 2014 at 10:39 AM 0
Share

Why did you convert it to an object in the first place?

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by fafase · Jul 16, 2014 at 12:44 PM

  Object foo = 100;

this is not possible, Object is Unity.Object, try to use object instead which is the mother class of all:

 object foo = 100;
 int bar = (int)foo;
Comment
Add comment · Show 4 · 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 YuyaOkada · Jul 16, 2014 at 01:18 PM 0
Share

I wanna use JavaScript. In JavaScript, I got this error.

var foo :object = 100;

'>> The name 'object' does not denote a valid type ('not found').

avatar image fafase · Jul 16, 2014 at 01:31 PM 0
Share

Well, I do not see any way for this to be possible in Us. You cannot explicitely cast and using as keyword is only for reference type.

There might be some ways I do not know about since I do not use Us. But this kinda tells me using C# is the right choice in the long run.

avatar image Landern · Jul 16, 2014 at 01:38 PM 0
Share

in unity script it appears the syntactic sugar for object(the sugar is referenced as System.Object in c#) is missing, so you will need to fully qualify with namespace and no sugar baby! You also don't want a conflict with UnityEngine.Object which would be the type selected if you use Object.

Example of usage:

 var b : System.Object = 1000;

avatar image YuyaOkada · Jul 17, 2014 at 07:55 AM 0
Share

Then, How can I convert System.Object into int in unity script?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

converting NavMesh to normal mesh? 0 Answers

RGB Colors as Float Values Converter 0 Answers

can i convert c sharp to javascript 2 Answers

need help converting JS to C 2 Answers

Help with converting JS to c# 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