Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Solved] Invalid AABB doing a rotation

Discussion in 'Data Oriented Technology Stack' started by MaskedMouse, Sep 15, 2018.

  1. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    541
    So I am pretty new to ECS, trying to understand it by re-creating examples & watching the Learn section videos about ECS & Job System.

    https://github.com/Unity-Technologi....Common/SimpleRotation/RotationSpeedSystem.cs

    But using the rotation code from the examples gives me a constant Invalid AABB error.
    Commenting out the rotation solves the error but then it doesn't rotate of course.

    I am uncertain why this is happening.

    Using Unity 2018.3.0b1

    Code (CSharp):
    1.  "com.unity.burst": "0.2.4-preview.30",
    2.     "com.unity.collections": "0.0.9-preview.5",
    3.     "com.unity.entities": "0.0.12-preview.13",
    4.     "com.unity.incrementalcompiler": "0.0.42-preview.21",
    5.     "com.unity.jobs": "0.0.7-preview.3",
    6.     "com.unity.mathematics": "0.0.12-preview.17",
    My prefab setup:
    ECS Prefab.png

    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Jobs;
    5. using Unity.Mathematics;
    6. using Unity.Transforms;
    7. using UnityEngine;
    8.  
    9. public class RotatorSystem : JobComponentSystem
    10. {
    11.     [BurstCompile]
    12.     struct RotateJob : IJobProcessComponentData<Rotation, RotationSpeedData>
    13.     {
    14.         public float DeltaTime;
    15.  
    16.         public void Execute(ref Rotation rotation, [ReadOnly] ref RotationSpeedData rotationSpeedData)
    17.         {
    18.             rotation.Value = math.mul(math.normalize(rotation.Value), quaternion.AxisAngle(math.up(), rotationSpeedData.RotationSpeed * DeltaTime));
    19.         }
    20.     }
    21.  
    22.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    23.     {
    24.         return new RotateJob { DeltaTime = Time.deltaTime }.Schedule(this, inputDeps);
    25.     }
    26. }
    Code (CSharp):
    1. using System;
    2. using Unity.Entities;
    3.  
    4. [Serializable]
    5. public struct RotationSpeedData : IComponentData
    6. {
    7.     public float RotationSpeed;
    8. }
    9.  
    10. public class RotationSpeedComponent : ComponentDataWrapper<RotationSpeedData> { }
    Code (CSharp):
    1. Invalid AABB result
    2. UnityEngine.Graphics:DrawMeshInstanced(Mesh, Int32, Material, Matrix4x4[], Int32, MaterialPropertyBlock, ShadowCastingMode, Boolean, Int32, Camera)
    3. Unity.Rendering.MeshInstanceRendererSystem:RenderBatch(Int32, Int32) (at Library/PackageCache/com.unity.entities@0.0.12-preview.13/Unity.Rendering.Hybrid/MeshInstanceRendererSystem.cs:630)
    4. Unity.Rendering.MeshInstanceRendererSystem:UpdateDynamicInstanceRenderer() (at Library/PackageCache/com.unity.entities@0.0.12-preview.13/Unity.Rendering.Hybrid/MeshInstanceRendererSystem.cs:613)
    5. Unity.Rendering.MeshInstanceRendererSystem:OnUpdate() (at Library/PackageCache/com.unity.entities@0.0.12-preview.13/Unity.Rendering.Hybrid/MeshInstanceRendererSystem.cs:823)
    6. Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.0.12-preview.13/Unity.Entities/ComponentSystem.cs:324)
    7. Unity.Entities.ScriptBehaviourManager:Update() (at Library/PackageCache/com.unity.entities@0.0.12-preview.13/Unity.Entities/ScriptBehaviourManager.cs:77)
    8. Unity.Rendering.RenderingSystemBootstrap:OnBeforeCull(Camera) (at Library/PackageCache/com.unity.entities@0.0.12-preview.13/Unity.Rendering.Hybrid/Rendering.Hybrid/
     
    Last edited: Sep 16, 2018
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,289
    Do you have Mesh Instance, or at laest Transform Matrix on your entity?
     
  3. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    541
    Edit:
    Hah I just found out what I did wrong!
    After looking at the prefab I saw the Rotation was 0,0,0,0.
    My spawning code did not include setting the rotation to
    Quaternion.identity
    . That was the problem.

    Edit 2:
    Setting the rotation to 0,0,0,1 by default in the prefab helps as well.
     
    Last edited: Sep 17, 2018
    Antypodish likes this.
  4. CaliburOne

    CaliburOne

    Joined:
    Nov 2, 2012
    Posts:
    6
    Found a issue related to this, it seems i get the same problem if i attempt to shear a 4x4matrix

    eg a matrix like this would create the same error
    1.00000 0.00000 2.00000 0.00000
    0.00000 1.00000 0.00000 0.00000
    0.00000 0.00000 1.00000 0.00000
    0.00000 0.00000 0.00000 1.00000

    EDIT:
    Looks like i'm wrong about the shear thing. It was a NaN that was making its way to Graphics.DrawMeshInstanced. If anybody runs into AABB error double check for NaNs.
     
    Last edited: Dec 21, 2018
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,507
    Gonna add some more. That's when you got NaN in the quaternion/something else.

    quaternion.LookRotation : if look at and up vector is collinear you get NaN. LookRotationSafe gives identity but bigger computation.

    Or look for 0 division.
     
  6. CaliburOne

    CaliburOne

    Joined:
    Nov 2, 2012
    Posts:
    6
    Thanks for the reply to this thread 5argon, it made me double check my code for NaNs and i ended up finding one.
     
unityunity