Search Unity

Unity C# source code

Discussion in 'General Discussion' started by konsic, Mar 26, 2018.

  1. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    Guess this saves me from having to download dotPeek. :p
     
    rakkarage likes this.
  3. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    This is stupid. What's the point of it, if
    "The terms of use do not permit you to modify or redistribute the C# code (in either source or binary form). If you want to modify Unity's source code (C# and C++), contact Unity sales for a commercial source code license: "

    And at the top says " May be used for reference purposes only.". So what's the point of them even showing any of them when you can't even be allowed to change something for your self.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    @N1warhead: I'm inclined to believe they're doing it because nothing was stopping people from doing it before when hunting down bugs though it could just be one step towards releasing the engine's source code down the road.
     
  5. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    @Ryiah : I suppose that is true.

    EDIT: Sorry, just really tired lol.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Probably because pretty much every programmer who gets in depth with Unity starts poking around in the C# source eventually. Its pretty much part and parcel of doing the job. Its difficult for Unity to prevent this from a technical or legal standpoint.

    Since everyone is doing it anyway, that might as well sanction it and make it easy to do.
     
    Ryiah likes this.
  7. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    It's very useful for seeing how they do certain things, like even relatively simple stuff like vector transformations and such.

    And much of that kind of thing is already public domain as far as the algorithms/math involved, with implementations being almost identical regardless of where the code came from. So there is just really no reason to hide it.
     
    angrypenguin likes this.
  8. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Honestly, I ain't never once tried to de-compile the Unity stuff and look at it. Never had a purpose too, don't generally run into many bugs though honestly. It's quite rare for me. Or perhaps the bugs that happen I didn't realize were bugs because they gave me the results I wanted hahha.
     
    Ony likes this.
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I just think its a nice base to understand what Unity is doing and copy some editor functionality if I need it.
     
    Deleted User, N1warhead and Kiwasi like this.
  10. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I used it just recently when I needed to duplicate some logic that was in non thread safe api's for jobs, and wanted to make sure I was using the same logic.
     
    angrypenguin likes this.
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    Is that permitted with this code though?
     
  12. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Exactly, says from my understanding that you can't lol.
     
  13. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    I think that's pretty self-explanatory, tbh:
     
    angrypenguin likes this.
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I probably will yeah, I'm sure Unity isn't gonna kick my ass for making internal Unity editor tools using Unity source. If they have to, they should tinker with the license until they don't :)
     
    Joe-Censored and Kiwasi like this.
  15. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    The question of can you use it depends. They aren't licensing what the code does in many cases, because they can't, it's already in the public domain. Doesn't matter that you might have learned about it from their code.

    You can't just copy it blatantly, but even then if there is really only one obvious way to implement it and that is what they did, then your implementation is probably gong to look the same.

    And all told I agree with @hippocoder, if you make use of it in the context of Unity, I doubt they will care. I doubt anything in that repo implements any approach not in the public domain already anyways so why would they.
     
  16. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I mean I get that, but still doesn't mean it has a point if you can't do anything with it.
    Like, for example, I see something in it I like, and want to make my own Method out of something in it, I can or can't do that?

    if not, it's just one more thing you guys have to manage that will slow progress down on other things if you guys make a lot of changes too the C# Source Code.

    Now if I can copy code from it and put it into something I'm making, then that's awesome.
    But it doesn't clearly state this as @hippocoder said.
     
  17. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    its just nice to have for reference, and in the past i did have cases where i had to look through the C# source, and make calls to some private or internal methods via reflection to accomplish what i needed.

    Also has helped me a lot understand the performance implications of calling certain unity methods
     
    Kiwasi likes this.
  18. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I mean, I see nothing wrong with using the code, and that's awesome if we can.
    But last thing I want is a 10 million dollar law suit hitting me because I had 1 line of code from it somewhere lol.
     
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah I think the point is pretty clear, to help Unity users do stuff with a reference, Unity really isn't going for people like you or me, we are the intended audience of this. Perhaps they need more lawyer time, I'll not worry.
     
    Ryiah, N1warhead and passerbycmc like this.
  20. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    If you read the code, and what you read helps you understand how to do something, and you implement your own stuff that makes use of that understanding, then that's fine.
     
  21. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    736
    The thing I would most like to see is the Mesh classes which I suppose is C++

    Pretty cool that the C# got released, I'll have to poke through it.
     
  22. Lu4e

    Lu4e

    Joined:
    Mar 23, 2018
    Posts:
    276
    The source reference should be useful for serious coding. Thanks for that.
    will us get paid for helping the debug?
     
  23. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  24. Lu4e

    Lu4e

    Joined:
    Mar 23, 2018
    Posts:
    276
    Not related to asset store, however Unity users are reporting issues more than developing their own games since 5.x, and this is also affecting vendors in asset store, keeping them busy on apply patches for different Unity versions.

    Since there are a lot of experienced users in the community, those may loyalty since Unity2.x.
    I would guess the commercial source code license is kind of bounty hunter recruitment for relieving the QA progress.
     
  25. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    For the most part source licenses are for developers who need the absolute best performance or need to support a use case that would otherwise be passed over by a company that is focused on developing a general purpose engine. Large companies are well known for this. Skyrim's Creation Engine, for example, is a heavily modified GameBryo.
     
    Last edited: Mar 26, 2018
  26. Lu4e

    Lu4e

    Joined:
    Mar 23, 2018
    Posts:
    276
    Oops, I thought the commercial source code license is kind of being Moderator and different from the source code access licence from Pro/Enterprise.
     
  27. WillNode

    WillNode

    Joined:
    Nov 28, 2013
    Posts:
    423
    Just a matter of fact, there was an unnoficial repo that does the same thing. It was there for three years before taken down by Unity a month ago. It surprises many people, even on reddit. I saw couple of good points of why it was popular and had raised more than a thousand stars in GitHub.

    ... then the official repo came out, which made everything makes sense.
     
  28. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    I have been to it multi times in the past.. sometimes from search engine in looking up a method to find some better documentation.. cus yknow official docs blow in comparison to api references with crowd source comments like php help docs etc.. way more useful.....still hadn't been unofficial github page in a while so never saw that it was taken down since last month... it makes the unity blog about them doing this as less yknow whats the word?.

    Because that action strikes me as stupid they would take down the existing third party managed github project when they hadn't even got there official one up for a month? did no one think to delay the email to legal team dawgs for a month or when they got the official github counter part up ? :cool:.. ..I'm guessing clearly not as they had a penny drop moment days or weeks after the project was shutdown at how stupid it was when nothing about the c# source is that protected.
     
    WillNode likes this.
  29. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    With how long they permitted it it's obvious Unity didn't care that it existed. They just issued the takedown because they wanted to provide it themselves and not have people going to one that was a reverse engineer instead of a true copy.
     
    WillNode and Lu4e like this.
  30. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    Only the unofficial one was shutdown a month ago.. I didn't notice.. but this official one was only announced today.. so timing was all off on that even if they were planning an official one.. They let the legal dogs out the cage ..on a takedown for something that didn't have a replacement yet.. did MattRx get a thank you letter, along with that takedown notice? :p
     
  31. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    Corporate latency.
     
    WillNode and Kiwasi like this.
  32. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    A month is pretty good latency for a corporation. I'm used to dealing in years.
     
    Ryiah likes this.
  33. Lu4e

    Lu4e

    Joined:
    Mar 23, 2018
    Posts:
    276
    A better way to do it, is publish the official repo, and politely ask the unofficial repo to redirect them without taken down. With the official repo, people has no reason to continue on the unofficial one.

    Not only the efficient way to spread the news for existing repo user, but also gaining Likes from them for such customer care.
     
  34. WillNode

    WillNode

    Joined:
    Nov 28, 2013
    Posts:
    423
    Sadly there is no definition for "polite" in terms of dealing with lawyers. It was taken down because it's "violates" the "do not distribute decompiled code" part. It's kinda sad that there always someone that makes creativity harder and complicated just because the law told them to do so.

    But hey, atleast Unity heard us. Now we have a very cool way to bringing attention for Unity to fix their bugs that stick for a looong time, like this one.
     
  35. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    Polite was allowing it to exist in the first place when it was clearly breaking the license agreement they would have signed.
     
  36. Lu4e

    Lu4e

    Joined:
    Mar 23, 2018
    Posts:
    276
    When a company already has an absolute rights, they could reserve it.
    Corporations law is used to prevent from losing profits, but in a wrong way could help them losing more.

    Today smart company has their corporate lawyer to learn PR, and a win-win result can gain positive reputation with increase of sales as well.
     
  37. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    But you can do something with it.

    For one instance, have you ever looked in the docs and found something ambiguous, unclear, or just plain missing? With this, instead of guessing or testing how it works for yourself, you can look at the code and see.
     
  38. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Which is where you find out that all the call does is pass an identical call into the C++ side of the engine, and you are stuck again. :p
     
    Ryiah, Lu4e, N1warhead and 1 other person like this.
  39. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    This is a nice move.

    Unity has a C++ core, a C# scripting Engine and a few other tools that work to together to produce the final result, which varies by platform.
    The code that is released has little to do with performance - the C++ core is the main determining factor. The caching method ArenMook contributed in pull requests section is an exception to the above statement.
    It does however provide most of the so far undocumented parts of Unity Editor methods - it is useful for people developing Editor Tools as a reference.
     
  40. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,269
    I do wonder at the lack of optimisation in places, although perhaps it can be explained how this is compiled out:

    Mathf:
    public static float Abs(float f) { return (float)Math.Abs(f); }

    I know most maths calls are just calls into the c̶+̶+̶ C# maths library but Abs is so simple this will waste a load of cycles going into the c̶+̶+̶ C# [double] function only to return "f > 0 ? f : -f"

    edited for not being awake
     
    Last edited: Mar 27, 2018
  41. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    Isn't unmanaged mathf library already in memory at that point?
     
  42. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    Math.Abs is part of the C# System namespace, so all it's doing is handling the casting from double to float for you, there's no C++ bridging happening. Chances are the compiler will automatically optimize the extra function call away for an actual build.
     
  43. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,269
    ah yes, ignore me then - some casting overhead but little else
     
  44. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    520
    Unity finally releases source code.

    The source code:

    Code (CSharp):
    1. public void Invoke(string methodName, float time)
    2. {
    3.     InvokeDelayed(this, methodName, time, 0.0f);
    4. }
    5.  
    6. [FreeFunction]
    7. extern static void InvokeDelayed(MonoBehaviour self, string methodName, float time, float repeatRate);
     
    TerraUnity, WillNode, FMark92 and 4 others like this.
  45. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    229
    Is the available source code complete?
    I'm looking for the RenderTexture source, more specifically ConvertToEquirect(), but it's not there.
    Some sources references [NativeHeader("Runtime/Graphics/RenderTexture.h")] but there's no Runtime/Graphics folder.
     
  46. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    No. Like the Github repo mentions this is just the C# side of the engine. The C++ side is still very much closed source.
     
  47. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    599
    I cannot tell you how many times being able to see into the Unity source code has simplified the things I have developed for Trilleon. It has saved me hours of work. Now, being able to modify it could, in very limited circumstances, be quite nice. I would love to be able to modify and enhance the EditorWindow system to make more visually appealing and reactive content in those - and then offer the new framework for it freely.

    But I definitely don't expect write access to anything Unity creates. I do expect read access to some of their code - but only because they present Unity as uniquely developer friendly. And I appreciate that.
     
  48. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    Just keep in mind the license hasn't changed. You're not actually allowed to modify it without a source license as mentioned in the readme for the repository. It's literally just a way to reference the source without having to use a decompiler. I'd love to eventually see that limitation go away.
     
  49. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    You can, however modify and use certain parts. For example, the ui.
     
    Ryiah and Kiwasi like this.
  50. Deleted User

    Deleted User

    Guest

    ive needed to reference the source quite a few times in the past, there is some things that was barely documented in the docs
     
    Ryiah likes this.