# GenerateKDopAsSimpleCollision() will create unbounded collision primitives under certain conditions

**URL:** <https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970>\
**Category:** World Creation\
**Tags:** unreal-engine, Collision, editor, CPP, question\
**Created:** [November 9, 2015, 8:55pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970 "2015-11-09T20:55:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfreeland.bhvr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sfreeland.bhvr](https://forums.unrealengine.com/u/sfreeland.bhvr)\
**Post date:** [November 9, 2015, 8:55pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/1 "2015-11-09T20:55:47Z")

</div>

Given a mesh and directions (projection axes) with certain properties as arguments, GenerateKDopAsSimpleCollision() will create a primitive collision that is essentially infinite. The culprit is the following block of code at GeomFitUtils.cpp:100

```
// Make sure that the min size is reached
// const float MinSize = 0.5f;
for(int32 i=0; i<kCount; i++)
{
    if (FMath::Abs(maxDist[i]) < MinSize)
    {
        maxDist[i] = MinSize;
    }
}

```

maxDist[i] is the maximum projection distances of the mesh’s vertex coordinates along one of the directions; this code finds any such value between -0.5 and 0.5 and clamps it to 0.5. If this happens, the FPlane created from that value may be pushed from the edge to the inside of the bounding polytope, thereby distorting the resulting collision primitive. In one case, we have found that it causes problems with the BSP build (GeomFitUtils.cpp:167) and ultimately results in the creation of _two_ separate collision primitives, one of which is effectively infinite:

 ![66191-unboundedcollision.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/5/5/955f0f40ff488a8d241c84cfa93da3ca5a671a15.png)

The intention behind that block of code is not at all clear to me, but commenting it out fixes the problem with no discernible side-effects so far.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [November 10, 2015, 5:44pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/2 "2015-11-10T17:44:14Z")

</div>

Hello sfreeland.bhvr,

What would be the best way to go about reproducing this issue? I have a simple grasp on what the result would be but not the steps to get there.

---

<div class="post-metadata">

**Author:** ![sfreeland.bhvr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sfreeland.bhvr](https://forums.unrealengine.com/u/sfreeland.bhvr)\
**Post date:** [November 10, 2015, 5:52pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/3 "2015-11-10T17:52:10Z")

</div>

Yeah, that’s the tricky bit of course. I’d like to give you a copy of the asset that triggered this problem, but unfortunately I can’t because it’s a customer’s IP. Basically you need to open a mesh with boundary vertices near (0, 0, 0) and generate a k-DOP collision primitive with it, such that the FMath::Abs(maxDist[i]) \< MinSize condition is satisfied. I was using the 26DOP collision generation when the bug manifested.

I’ll try to put together a simple test case that I can release to you.

---

<div class="post-metadata">

**Author:** ![sfreeland.bhvr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sfreeland.bhvr](https://forums.unrealengine.com/u/sfreeland.bhvr)\
**Post date:** [November 10, 2015, 6:20pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/4 "2015-11-10T18:20:33Z")

</div>

I haven’t been able to create a test case to reproduce the unbounded collision from the screenshot, but compare the following two FBX files:

> **[Google Drive: Sign-in](https://accounts.google.com/v3/signin/identifier?dsh=S-972954843%3A1682008725267579&continue=https%3A%2F%2Fdrive.google.com%2Fdrive%2Ffolders%2F0B9VvF0LqvxptT2hLWk1rMVZubUE%3Fusp%3Dsharing&followup=https%3A%2F%2Fdrive.google.com%2Fdrive%2Ffolders%2F0B9VvF0LqvxptT2hLWk1rMVZubUE%3Fusp%3Dsharing&ifkv=AQMjQ7RxxAdKpqxuvxbra26v5qobyh73PNhk0yYGgspX2J0bIVPVPfxA3aK1hmCxygyLrPzzltdtPw&osid=1&passive=1209600&service=wise&flowName=GlifWebSignIn&flowEntry=ServiceLogin)**
>
> Access Google Drive with a Google account (for personal use) or Google Workspace account (for business use).

If you import them, open them in the mesh editor and create a 26DOP collision for each, you can see that the resulting mesh is distorted in the case of “uebug2” because of its proximity to the origin. “uebug-ok” on the other hand, gets a good, close collision primitive because it’s further from the origin, even though the shape of the mesh is exactly the same.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [November 10, 2015, 8:30pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/5 "2015-11-10T20:30:04Z")

</div>

Thank you for reporting this issue and being very thorough with the reproduction steps / setup. I definitely see the problem and I’ve placed a bug report in for the issue. For your reference, the bug number is UE-23176. While I’m not sure about the reason for that for loop, I’ll let you know of any updates that happen to the report, as this could be intended functionality meant to simplify the process.

Have a nice day!

---

<div class="post-metadata">

**Author:** ![sfreeland.bhvr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sfreeland.bhvr](https://forums.unrealengine.com/u/sfreeland.bhvr)\
**Post date:** [November 11, 2015, 2:01am UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/6 "2015-11-11T02:01:55Z")

</div>

Glad to be of service, and I appreciate your letting me know what happens to this issue.

---

<div class="post-metadata">

**Author:** ![Dig\_Squid](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig_squid/32/1145423_2.png) [@Dig\_Squid](https://forums.unrealengine.com/u/Dig_Squid)\
**Post date:** [February 3, 2016, 2:10pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/7 "2016-02-03T14:10:38Z")

</div>

I believe the intention of this (rather old) code was to prevent any ‘slabs’ being zero width and causing issues in the collision code. I am going to remove the Abs, which should at least solve the degenrate case, but does mean that your kdop is built around the mesh and a sphere of radius 0.5 at the origin. Ideally we would just ensure each ‘slab’ width is at least some min size, but that requires knowledge of opposing directions which we don’t currently have and would be a large refactor.

Anyway, thank you very much for the bug report, it is much appreciated.

---

<div class="post-metadata">

**Author:** ![Dig\_Squid](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig_squid/32/1145423_2.png) [@Dig\_Squid](https://forums.unrealengine.com/u/Dig_Squid)\
**Post date:** [February 3, 2016, 2:42pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/8 "2016-02-03T14:42:45Z")

</div>

Actually after thinking about it some more, that isn’t a great fix. Instead I’m just going to inflate the kdop by minsize to ensure non-degenerate slabs.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [February 26, 2016, 7:06pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/9 "2016-02-26T19:06:46Z")

</div>

Hello sfreeland.bhvr,

A fix has gone in for this issue now so it should be included in a future build. As of now, the change isn’t available on Github but I’ll keep an eye out and link the commit here when it is if you wish to add it to a source built engine.

---

<div class="post-metadata">

**Author:** ![sfreeland.bhvr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sfreeland.bhvr](https://forums.unrealengine.com/u/sfreeland.bhvr)\
**Post date:** [March 1, 2016, 2:53pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/10 "2016-03-01T14:53:30Z")

</div>

Thank you for the follow-up! I’ll be interested to see how this gets fixed.

---

<div class="post-metadata">

**Author:** ![sfreeland.bhvr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sfreeland.bhvr](https://forums.unrealengine.com/u/sfreeland.bhvr)\
**Post date:** [April 11, 2016, 3:48pm UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/11 "2016-04-11T15:48:24Z")

</div>

Hi JamesG, I just noticed that a fix for this issue was committed on github:

.com/EpicGames/UnrealEngine/blob/master/Engine/Source/Editor/UnrealEd/Private/GeomFitUtils.cpp#L101

I’m curious though – what happens if maxDist is less than zero, say for instance because the mesh is entirely contained within the negative x/y/z octant of the coordinate space?

---

<div class="post-metadata">

**Author:** ![Dig\_Squid](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig_squid/32/1145423_2.png) [@Dig\_Squid](https://forums.unrealengine.com/u/Dig_Squid)\
**Post date:** [April 24, 2016, 5:03am UTC](https://forums.unrealengine.com/t/generatekdopassimplecollision-will-create-unbounded-collision-primitives-under-certain-conditions/337970/12 "2016-04-24T05:03:53Z")

</div>

I think that should still work, because maxDist is the distance along the normal, it is basically pushing all planes out along their normal.
