Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unity Open Source code is missing implementations?

Discussion in 'Scripting' started by NornIndustries, Mar 25, 2020.

  1. NornIndustries

    NornIndustries

    Joined:
    Jun 25, 2014
    Posts:
    5
    I'm not sure if this is the right forum to put this question.

    Following this develoment blog, I'm having trouble finding the implementation of some functions in Unity's open source code.

    I am trying to create duplicate vector classes (like a duplicate for Matrix4x4), which essentially replace float data types with longs, and change various equations where necessary to make deterministic outcomes.

    The problem is some of the functions have interfaces which lead to dead ends, and I can't find the implementations of various critical functions used in Vector2, Vector3, Matrix4x4. For example, Matrix4x4.inverse or Matrix4x4.TRS. Also would be great to see the nuts and bolts of Raycast.

    It just seems odd that Unity declared that they had released the code so people could see it, and will keep it regularly updated... and much of it is missing.

    Is there something I have missed, or is this code not actually released with the "open source" code release (why not)? Or is this code only accessible for pro version or something like that?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,385
    So I'll first point out that the source code you're referring to is NOT "open source". That blog post you linked explicitly states that:

    They suggest you look through their license as well:
    https://unity3d.com/legal/licenses/...194.118266803.1583889133-803250843.1563326041

    Some may argue basing new code off of existing code isn't modifying existing code. Since the original code still exists and is ran in its original state... but is still a grey area on if it's actually allowed. So just be aware of that, what you're doing may technically be breaking the Unity license.

    Personally my approach would be the "mono way". Where mono when originally porting the .net framework utilized the same interface of all types (same member names/types/etc). But the implementation was custom. This way the 'shape' of the type was compatible with .net, but its underlying implementation was wholely new and unique to the mono teams efforts.

    So to I would do with the Unity stuff. You want your own Matrix4x4, you follow the same shape for compatibility/consistency. But your implementation should be based on your own efforts. And things like calculating the "inverse matrix" or creating a matrix from "TRS - translation, rotation, scale" are basic mathematical processes that you can find definitions for on the internet at places like wikipedia.

    ...

    With that said.

    Methods like Matrix4x4.Inverse and TRS, are actually implemented on the internal unmanaged side of Unity.

    Note that this source code they released is ONLY the "managed code":
    Managed assemblies basically means... the code they wrote in C# and runs in the .net/mono runtime (or would be cross-compiled via IL2CPP).

    The unmanaged code is the code written primarily in C++. Access to that code requires a special license that is directly negotiated with Unity.

    So if you were allowed to base code off their existing code... the code you're looking for is not released.
     
    Last edited: Mar 25, 2020
    NornIndustries and Suddoha like this.
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    The functions you're referring to are usually declared as extern functions and thus their implementation exists in the native source code. Native source code is AFAIK not available unless a license is purchased.

    The theory for replication of such functionalities can be found all over the web. It may take some time to find an appropriate explanation for an efficient implementation, especially with the requirement of using fixed-point arithmetic which you seem to go for, apparently.

    The declaration of these functions can be found in separate binding files, such as the one for mathematical operations.

    *edit Lord was faster.
     
    NornIndustries likes this.
  4. NornIndustries

    NornIndustries

    Joined:
    Jun 25, 2014
    Posts:
    5
    Thank you for clarifying that @lordofduct and @Suddoha I misunderstood the distinction they made between managed and unmanaged. Back to the drawing board for bespoke solutions.