Search Unity

Question What the different between Unity.Profiling and UnityEngine.Profiling?

Discussion in 'Editor & General Support' started by watsonsong, Sep 8, 2022.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I find there has two different namespace in Unity abour profiling: Unity.Profiling and UnityEngine.Profiling
    What the different about them. Why they put into different namespace? Is there any design purpose?
    What the best practice when I use them? For example the ProfilerMarker.Begin or Profiler.BeginSample
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,930
    Probably just some architectural reason. Most likely there was going to be a circular reference or something between assemblies, so common functionality was moved into a lower level assembly.
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,460
    The switch to the Unity namespace came about with DOTS and packages. Anything in the Unity. Namespace should be either detangled from UnityEngine.Objects or in a package.

    There's also the difference of camelCase (UnityEngine) vs PascalCase (Unity) for public properties.

    As for Profiling, the Unity namespace is where the Burst compatible APIs and the profiler packages live.

    Another way to look at it is for profiling: if there is something in the Unity namespace that does the same as something in UnityEngine namespace, you should probably use the solution in the Unity namespace, as that's likely newer and with a lower instrumentation overhead (and Burst compatible).
     
    Fribur likes this.
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,460
    Speaking of instrumentation overhead:
    Profiler.BeginSample is handy but has a way higher instrumentation cost than ProfileMarker.Begin, among other things because it has to send the name to the native backend, instead of a marker ID.
     
    Fribur likes this.