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
2
Question by Fattie · Nov 19, 2012 at 10:05 AM · javascriptreferenceunity4outref

Unity4, Unityscript added "ref" or "out" keyword?

Attention, advanced Unity developers!!

As you already know, Unityscript does not support passing by ref to functions

Does anyone know,

Have Unity recently added this to Unityscript - perhaps in U4 ??

I tried all the obvious keywords (ref, out, etc)

It is undocumented so maybe they have added it, but I just don't know the keyword.

Cheers!!

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 Eric5h5 · Nov 27, 2012 at 01:25 AM 0
Share

If they'd been added, it would have been in the release notes.

1 Reply

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

Answer by YM_Industries · Nov 19, 2012 at 11:45 AM

Unityscript does not have any way for passing parameters by reference.

If you must have By Ref arguments, C# supports them.

EDIT: Actually, on further investigation, there may be support for these. The built-in function Physics.Raycast() can be in the form

 static function Raycast (origin : Vector3, direction : Vector3, out hitInfo : RaycastHit, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : boolean

Notice the 'out hitInfo' argument. This appears to be ByRef. I have no idea how this can be achieved in a custom function, but it does appear to be possible.

EDIT 2: Eric5h5 has kindly offered some clarification in the comments, I'll sum it up here: If you define your function in JS/US, it cannot utilise ByRef parameters. However, if your function is defined in C#, you can call it from JS/US with Out parameters that are ByRef.

Comment
Add comment · Show 14 · 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 Fattie · Nov 19, 2012 at 12:18 PM 0
Share

Hiya. You're quite sure it has not been added in U4 ?

avatar image Berenger · Nov 19, 2012 at 12:39 PM 0
Share

Is it specific to the language, or is it .Net ?

avatar image Eric5h5 · Nov 27, 2012 at 01:25 AM 1
Share

You can use ref and out parameters in JS, but you can't declare them in functions. This means you can have functions in C# scripts which use ref or out parameters and use them in JS with no issues.

avatar image Eric5h5 · Nov 27, 2012 at 01:31 AM 1
Share

No, they are declared in the C# function. There is no mechanism for declaring ref or out variables in JS.

avatar image Eric5h5 · Nov 27, 2012 at 01:36 AM 1
Share

No, aside from variables which are always passed by reference anyway, such as arrays or classes. Structs and primitive types are always by value.

Show more comments

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

13 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

Related Questions

Long-term use of ref/out? 1 Answer

Your "own" structs ... are they indeed passed by value? 1 Answer

NullReferenceException: Object reference not set to an instance of an object - MonoBehaviour 2 Answers

Is it possible to pass a variable by reference in javascript 1 Answer

Pass class and component reference from inside class 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