Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by Peter G · Jul 30, 2011 at 04:10 AM · virtual functions

Why are Unity functions implicitly virtual

According to this page, all Unity functions are virtual:

All functions are now implicitly virtual, as a result the 'virtual' keyword has been deprecated and the 'final' keyword has been introduced to allow for non virtual methods to be defined as:

I'm curious as to the design goal in doing this. This is obviously the opposite of traditional C# syntax (or js for that matter). I know there is a small overhead to calling virtual functions, but I doubt that played a significant role in the decision to switch this standard.

So my question is simply why make this change, and does anyone actually use the final keyword? Should I be because I would end up putting it on most of my methods?

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

Answer by SilverTabby · Jul 30, 2011 at 04:31 AM

I think it's ease of use is the main thing they were looking for when they made everything virtual.

You'll notice that on the wikipedia page for virtual functions all of the (in my mind at least) "simple" and "ease of use" languages like java, python, etc. have things as virtual by default while the "controlling", "arcane" languages like C++, C#, etc. force you to define a function as virtual by hand.

Unity seems to want to bring game design to the masses: It's free and it uses simple concepts and a simple scripting system. Throwing the idea of Virtual/Non-virtual at the average joe is the easiest way to scare him off.

Also I come from a java background and I think you're crazy for ever writing a function that you don't want overridden :|

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 Peter G · Jul 30, 2011 at 02:21 PM 0
Share

You are probably right, but since we're here, this is an interesting SO thread arguing the opposite.

avatar image Peter G · Jul 31, 2011 at 02:46 PM 0
Share

Well I find myself leaning towards the SO pages argument, but it is what it is.

avatar image SilverTabby · Jul 31, 2011 at 06:31 PM 2
Share

I still don't see any advantage to the argument in the SO page, in my $$anonymous$$d it honestly feels like a weaker argument than ease of use.

I think it all comes down to the people with C/C++/C#/etc. coding backgrounds like to control EVERYTHING while people from java/python/javascript/etc. backgrounds don't want to control it if they don't have to (you can argue that we're too lazy :P).

C: "Does it work? Yes. Now then, is it perfect? No. I must fix it!"

python: "Does it work? Yes. Now then, where did I hide the Ice cream?"

avatar image
4

Answer by Dreamora · Jul 31, 2011 at 03:20 PM

for UnityScript it made sense to be virtual cause it has not the full set of capabilities to handle the situation as C# does.

Also UnityScript and Boo are "UTs babies" (UnityScript directly and Boo cause its inventor and maintainer happens to be the same guy handling UnityScript and works for UT ;)) and they can go with them where they should go best because they don't have to comply to other standards and more importantly other compilers.

Just cause Virtual is bad on C# with an overhead, the same does not needfully stand correct for UnityScript as nothing forces the compiler to be "stupid" and output it as virtual if no overload is being found for example as it does not have to comply to other standards that would cause that problem.

UnityScript always has been searching for "automagic" as I tend to call it. Don't offer an option to the user he does not needfully require if you can do it all under the hood if we can easily do by inspecting the code and if you ask me it makes sense that UnityScript goes that way as its not targeted at hardcore programmers and professionals which would work with C# for various reasons anyway, UnityScript is there to be easy to those new to unity, new to scripting, coming from web JS scripting or AS3 :)

Look at properties of structs for example which require temp assignements on C# but not on UnityScript and similar things

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 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