JavaScript Quirks

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Joseph05408 (Talk); changed back to last version by KeliHlodversson)
m (added UnityScript notice)
 
Line 1: Line 1:
 +
{{delete}}
 +
{{UnityScript Notice}}
 +
 +
 
*Only Monobehaviours can use print(). This means that if you're using a custom class and need to debug it, you need to use [http://unity3d.com/Documentation/ScriptReference/Debug.Log.html Debug.Log(str)] instead. This will work both inside MonoBehaviours and non-MonoBehaviours alike.
 
*Only Monobehaviours can use print(). This means that if you're using a custom class and need to debug it, you need to use [http://unity3d.com/Documentation/ScriptReference/Debug.Log.html Debug.Log(str)] instead. This will work both inside MonoBehaviours and non-MonoBehaviours alike.
 
*If a class inherits from another class, and an instance is explicitly declared as the parent class, it will always call the parent's function - even if the child overrides it! The workaround is to make the instance a typeless variable. (The easiest way is to define the type as ''object'': '''var variable_name : object;''')
 
*If a class inherits from another class, and an instance is explicitly declared as the parent class, it will always call the parent's function - even if the child overrides it! The workaround is to make the instance a typeless variable. (The easiest way is to define the type as ''object'': '''var variable_name : object;''')
 
:This problem will disappear when Unity's JavaScript implements equivalents to the ''new'', ''override'' and ''virtual'' method qualifiers in C#.
 
:This problem will disappear when Unity's JavaScript implements equivalents to the ''new'', ''override'' and ''virtual'' method qualifiers in C#.
 
* Unity JavaScript uses static typing but avoids having to define the types by using [[JavaScript Type Inference|type inference]] where it can and reverts to dynamic typing (or duck typing) where the inference doesn't work.
 
* Unity JavaScript uses static typing but avoids having to define the types by using [[JavaScript Type Inference|type inference]] where it can and reverts to dynamic typing (or duck typing) where the inference doesn't work.
 +
 +
[[Category: Legacy]]

Latest revision as of 20:08, 21 November 2018

This page is marked for deletion

End of support for UnityScript

Starting with Unity 2018.2, support for UnityScript (Unity's version of JavaScript) has ended. C# is now the only supported language going forward. You can learn more about the reasons for this change here. There is an official UnityScript-to-C# Automatic Conversion tool to help those wanting to transition their UnityScript projects over to C#.


  • Only Monobehaviours can use print(). This means that if you're using a custom class and need to debug it, you need to use Debug.Log(str) instead. This will work both inside MonoBehaviours and non-MonoBehaviours alike.
  • If a class inherits from another class, and an instance is explicitly declared as the parent class, it will always call the parent's function - even if the child overrides it! The workaround is to make the instance a typeless variable. (The easiest way is to define the type as object: var variable_name : object;)
This problem will disappear when Unity's JavaScript implements equivalents to the new, override and virtual method qualifiers in C#.
  • Unity JavaScript uses static typing but avoids having to define the types by using type inference where it can and reverts to dynamic typing (or duck typing) where the inference doesn't work.
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox