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 KaiserAfini · May 10, 2015 at 03:37 PM · javascriptreflectionmathfinvokelibraries

How do I get the system type of Mathf in JS ?

I am attempting to call a function in Mathf by utilizing its string name, which requires the use of the Invoke function. However, before I can do this, I need to get the type of Mathf:

 var mathLibrary : System.Type = System.Type.GetType("System.Type.Mathf");

However, no matter if I use "Mathf", "System.Mathf" or even "Type.Mathf", this function always returns null. What is the correct syntax ?

Thank you in advance and have a nice day

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
1
Best Answer

Answer by fafase · May 10, 2015 at 04:21 PM

So first off Mathf is not from System, which is one reason it does not find it. Math is in System but Mathf is in UnityEngine.

Second, it seems GetType requires extra info when dealing with custom classes/structs. By custom I mean anything that is not in .NET. Here is what it wants: "UnityEngine.Mathf, UnityEngine"

So this should go fine (it does for me):

 var mathLibrary : System.Type = System.Type.GetType("UnityEngine.Mathf, UnityEngine");
 Debug.Log(mathLibrary == null);
Comment
Add comment · Show 5 · 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 KaiserAfini · May 10, 2015 at 04:42 PM 0
Share

Awesome, that did it, thank you so much, this was driving me crazy since I couldn't find any documentation on $$anonymous$$athf's location. Could you please indicate where you got that info ? It would be a huge help for future research

One more question, first I am checking if the method exists in $$anonymous$$athf, but when I test with $$anonymous$$ax, since it has 2 overloads, I get an ambiguity exception. But solving the ambiguity would involve evaluating the parameters in my custom parsing system (which, in addition to text expressions, also parses a custom class that extends $$anonymous$$onobehaviour) before trying to find the function, which seems very wasteful, is there an alternative ?

avatar image Bunny83 · May 10, 2015 at 05:10 PM 1
Share

@$$anonymous$$aiserAfini:

If a method has one or several overloads the compiler has to pick the right one based on the passed parameters. There's no way around that. Or how should you pick the right "$$anonymous$$ax" method if you don't know if you're going to pass integers or floats.

btw: if you actually hardcode that line in your question you don't have to use System.Type.GetType. Just use

 // UnityScript
 var mathLibrary : System.Type = $$anonymous$$athf;

 // C#
 System.Type mathLibrary = typeof($$anonymous$$athf);
avatar image KaiserAfini · May 10, 2015 at 05:14 PM 0
Share

Cool, thanks again

avatar image fafase · May 10, 2015 at 05:35 PM 1
Share

Concerning how I know that $$anonymous$$athf is not .NET, well because it cannot be found there :) and also because .NET already has $$anonymous$$ath so there would be little reason to have a $$anonymous$$athf there. Actually, $$anonymous$$athf is mostly wrapping $$anonymous$$ath class most likely with some specific considerations for Unity.

Finally, a good way to know about classes and structs, the documentation may give hints or do a right click on the class and select Go to Declaration. It will open the assembly browser containing some extra info. $$anonymous$$ost of the time, it contains only the big idea of a class as most of it is in C++.

avatar image Bunny83 · May 11, 2015 at 04:13 AM 0
Share

If you want to know how a certain class is implemented, just download ILSpy and open the UnityEngine.dll. ^^

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

2 People are following this question.

avatar image avatar image

Related Questions

How to loop a function? 2 Answers

Reopening a project causes it to raise a ReflectionTypeLoadException 0 Answers

A small spawning challenge.. 5 Answers

iOS Reflection Code stripping problem 2 Answers

MathF clamp not working 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