Search Unity

Overlapp AABB , error (Solved)

Discussion in 'Physics for ECS' started by GameMadeByGamers, Apr 9, 2020.

  1. GameMadeByGamers

    GameMadeByGamers

    Joined:
    Nov 25, 2014
    Posts:
    54
    Im getting the following error while trying to execute overlapAABB :
    ArgumentException : SliceStart + Length (7) range must be <= array.Length (5)

    The full OnUpdate method (https://pastebin.com/DdwpnwZC)
    Code (CSharp):
    1.        
    2.             NativeList<int> hitsIndices = new NativeList<int>(Allocator.Temp);
    3.  
    4.             CollisionFilter filter = new CollisionFilter
    5.             {
    6.                 BelongsTo = 3,
    7.                 CollidesWith = 3,
    8.                 GroupIndex = 0
    9.             };
    10.             //Check for nearby unitsgroup already existing
    11.             Aabb aabb = new Aabb
    12.             {
    13.                 Min = translation.Value + new float3(-castRadius, 0, -castRadius),
    14.                 Max = translation.Value + new float3(castRadius, 1, castRadius)
    15.             };
    16.             OverlapAabbInput overlapAabbInput = new OverlapAabbInput
    17.             {
    18.                 Aabb = aabb,
    19.                 Filter = filter,
    20.             };
    21.  
    22.             bool haveHits = collisionWorld.OverlapAabb(overlapAabbInput, ref hitsIndices);
    23.  
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Is it possible that some other system that was run after the physics step removed some of the bodies and that your collision world is not up to date with it? Collision world internally holds a hierarchy of bodies, so if the original body buffer changes, collision world needs to be rebuilt in order to "see" those changes...
     
  3. GameMadeByGamers

    GameMadeByGamers

    Joined:
    Nov 25, 2014
    Posts:
    54
    Well i do instantiate new UnitsGroup(s) containing a collider but this occur after this system.
     
  4. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yeah I'm mostly referring to stuff done during the physics step or before this system... Which physics version are you using?
     
  5. GameMadeByGamers

    GameMadeByGamers

    Joined:
    Nov 25, 2014
    Posts:
    54
    Im using Unity physic 0.3.1.
     
  6. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Could it be that your system isn't scheduled properly, so it runs in parallel with the next physics step? All physics related systems should happen before EndFramePhysicsSystem, and you can ensure that by using UpdateBefore and also adding this system's handle to the EndFramePhysicsSystem.HandlesToWaitFor... Let me know if this changes anything.
     
    cultureulterior likes this.
  7. GameMadeByGamers

    GameMadeByGamers

    Joined:
    Nov 25, 2014
    Posts:
    54
    Ok so i added the following decorators
    "[UpdateBefore(typeof(EndFramePhysicsSystem)), UpdateAfter(typeof(StepPhysicsWorld))]" and added to the dependency the finalHandler of the BuildPhysicWorldSystem.

    Code (CSharp):
    1.         Dependency = JobHandle.CombineDependencies(Dependency, buildPhysicsWorld.FinalJobHandle);
    2.         Dependency = JobHandle.CombineDependencies(Dependency, FindUnitsGroupInProximiyJobHandle);
    3.         endSimulationEcbSystem.AddJobHandleForProducer(this.Dependency);
    Everything seem to be working correctly thanks for the help!