UPrimitiveComponent::SetCollisionEnabled has inconsistent behaviour depending on actor collision state

I’ve noticed that calling UPrimitiveComponent::SetCollisionEnabled can have inconsistent behaviour if you’re also changing the collision state of the actor itself. The reason for this is that the function checks if the new collision state differs from the current one, but actually checks the actor’s collision state rather than the component’s. So if you attempt to set, for example, NoCollision, but the actor currently is set to have collision disabled, then the change is ignored, even though you’re trying to change the component collision specifically. Then if you turn the actor collision back on, the component collision won’t be in the state you expect.

This is simple enough to fix, we can just change the first line of the function from

ECollisionEnabled::Type CurrentType = BodyInstance.GetCollisionEnabled();To

ECollisionEnabled::Type CurrentType = BodyInstance.GetCollisionEnabled(false);And then we correctly check against the component’s collision state.

However, the reason I ask this question is that this has actually come up twice on UDN before:

[Content removed]

[Content removed]

In both cases the responder agreed that this looks like a bug, and in the first case there was an issue created, but it was closed as won’t fix almost 2 years later.

I can make this change myself, but I’m curious as to whether there’s some reason this change wasn’t made by Epic. It makes sense that true would be passed to check the actor collision state by default, as externally you want the primitive to appear to have no collision if the actor has all collision disabled. However I don’t think it makes sense in this function, but it could be that I’m just missing something.

Thanks!

Dan

Steps to Reproduce
Call SetActorEnableCollision(false) on an actor with a primitive component set to have collision initially enabled

Call SetCollisionEnabled(ECollisionEnabled::NoCollision) on the primitive component of that actor

Call SetActorEnableCollision(true) on the actor to re-enable collision

The primitive component will still have its initial collision state (The call to SetCollisionEnabled was ignored)

Hi [mention removed]​,

Thanks for the report. I was able to confirm this behavior in UE 5.5, 5.6, and in a recent source build from the Main stream (CL 45595284). I am re-submitting this bug, since the prior bug report on this topic (UE-83420) was tied to UE4 and closed without a fix, even though Epic staff also recognized it as an issue in the UE5 preview ticket you referenced.

As a workaround, modifying SetCollisionEnabled to call BodyInstance.GetCollisionEnabled(false) ensures the comparison is done against the component’s own collision state, which resolves the problem locally.

I’ve submitted this as an engine bug so the team can review and resolve it. You can track it here: Unreal Engine Issues and Bug Tracker (UE\-326835\).

Please note that Epic ultimately decides whether the ticket will be made public, so the link may take a few days to become accessible.

I’ll close the case now, but feel free to reply if you have anything else to add.

Best,

Francisco