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. Dismiss Notice

Resolved What is the difference between UnityEngine.Quaternion and Unity.Mathematics.quaternion?

Discussion in 'Entity Component System' started by Palom-Porom, Sep 1, 2023.

  1. Palom-Porom

    Palom-Porom

    Joined:
    Sep 21, 2022
    Posts:
    33
    I heard that Unity.Mathematics.quaternion is more effective in BurstCompiled code than UnityEngine.Quaternion, but I am not sure. Also I wonder if it is okay to use Quaternion instead of quaternion, as the first one has much more functions in it?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,556
    If you want to use burst, you need to use math.quaternion.
    Otherwise you loose your performance opportunity.
    And yes quaternion has fewer methods than Quaternion. But some these are relocated in different part of math library.
    Usually it enough for most of your game logic. Also other burst compatible libs are available online, on various sources.
     
    Palom-Porom likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Burst can generate more performant code if being precise.

    Quaternion will work just fine as any struct inside Burst compiled code would. Just not as performant as quaternion counterpart. Speedwise - depends on what kind of operations are performed and number of them. Sometimes there's no (or minimal) difference at all.

    math lib works as a "hint" for the Burst compiler.
    Sometimes its just smart enough to figure out what's going on based on data types of underlying operations.
     
    Palom-Porom likes this.