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 ina · Apr 07, 2012 at 09:37 PM · c#raycastraycasthit

C# out hit for raycasthit - why is the out needed, what does it go

I notice that RaycastHit is called differently for JS vs C#... In C#, the hit is actually out hit ... what does the out do, and why is it needed?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by rutter · Apr 07, 2012 at 11:07 PM

Most function arguments are passed by value -- that is, you pass a copy of the original value, rather than the variable itself. Changes made to that copy won't be reflected in the original variable unless your code does so explicitly.

Some functions accept arguments that are passed by reference -- instead of a copy, you pass the original variable itself. Changes made in the called function will be reflected in the original variable.

C# and UnityScript both typically pass by value, unless the called function explicitly tells the compiler to pass by reference. C# is unique in that it requires coders to explicitly pass by reference on both sides of the call -- I assume the idea is to make sure that you know you're doing so, as it can sometimes lead to confusion.

Ultimately, both languages are doing the same thing. C# just has a slightly different syntax for doing so.

Comment
Add comment · Show 3 · 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 AirZo · Jun 08, 2015 at 02:45 PM 0
Share

what if I don't add the out before the hit? are there any effect?

avatar image Landern · Jun 08, 2015 at 02:48 PM 0
Share

Sure, you will get an error. Out forces a variable to be passed by reference, the difference between using out or ref is that ref requires the variable to be initialized first, out doesn't(meaning it can be null or whatever the default state of the variable is).

avatar image AirZo · Jun 09, 2015 at 02:24 AM 0
Share

what should i initialize if i use ref?All of the variables in hit?

avatar image
0

Answer by kyon77 · Apr 08, 2012 at 12:20 AM

As far as I know, the Out gives you the info about what it hit, like the distance to the hit, the name of the object it hit, the point where it hit, and so on.

It can be very helpful in some cases where you wanna know if a laser hit a friendly target or an enemy, for example.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i use raycast hit to detect object by the object tag name ? 1 Answer

C# change an object tag wit raycasthit. 2 Answers

RaycastHit: What is the difference between hit.transform.tag and hit.collider.tag, and which should I use when? 1 Answer

Raycast executing hundreds of times 2 Answers

Another Raycast Issue. 0 Answers


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