Set Collision Profile Name not working

Hello. I have a simple Actor BP with a Static Mesh Component, for which I want to be able to change Collision in Construction Script via a simple bool parameter (default true).

Here is the Component’s initial Collision setup:

305129-ue4editor-2020-06-22-16-52-33.png

And here’s the Construction Script logic:

I can’t get it to work both ways. After first placing the Actor it has collision, and after unchecking the “Collision” bool collision disappears as expected. But after checking “Collision” back to true, collision is still disabled and if I view the Actor’s Component’s settings it’s still set to NoCollision, even though I see the Flow animation to the “SetCollisionProfileName BlockAll” node in the Construction Script graph.

The results are sometimes inverted, e.g. if I change the Component’s initial Collision Preset from BlockAll to Custom, then the “False” part of my graph stops doing anything - suddenly it’s impossible to disable collision.

All in all I tried many different configurations, including the SetCollisionEnabled and SetCollisionResponseToAllChannels (this one I’d like to avoid) nodes, but I can’t get it to work both ways.

I’ll appreciate any help. Thank you in advance.

Strange. I tried and it works as expected.

Well I tried it on a fresh BP and even in a different project and it still doesn’t work for me.

Repro:

  1. Create a new Actor BP
  2. Add a Plane component
  3. Add a Boolean parameter, name it “Collision”, make it public and set its default value to True
  4. In Construction Script, recreate the nodes from my screenshot (Branch on the “Collision” bool, True leads to SetCollisionProfileName “BlockAll”, False leads to SetCollisionProfileName “NoCollision”, both with the Plane component as Target)
  5. Compile the BP
  6. Place the BP in a Level
  7. Uncheck the Actor’s “Collision” parameter (set False), verify collision. Check it back (set True) and verify again. You can verify e.g. by placing the BP in the air and trying to paint Foliage on it, or simply by navigating to the Plane component and observing the Collision settings.

Observed results: the Plane component gets stuck on “BlockAll”, always has collision

Expected results: the Plane component’s Collision settings toggle between “BlockAll” and “NoCollision”

Yes, you are right. So, set the plane’s collision to BlockAll and try this:

Well, at least this works, yes, thank you. But I need more granular control over collision, with certain channels ignored and others blocked. That’s why I’d like these to work:

  • SetCollisionProfileName
  • SetCollisionResponseToAllChannels
  • SetCollisionResponseToChannel

EDIT: My observations in this post are somewhat erroneous. Check my follow up post for the solution to the problem I was experiencing.

I’m experiencing a similar issue with the “Set collision profile name” node and applying forces.

I set to the “NoCollision” profile on my static mesh and stop simulating physics on my capsule (I apply forces for capsule only). Then I change back to “BlockAllDynamic” on my static mesh and start simulating physics on my capsule. My BPs that apply forces seem to be executing normally, but the actor moves at about 1/1000 of the speed.

This happens also if I don’t touch the physics at all:
Change profile to “NoCollision” > Delay > change to “BlockAllDynamic”

If I change to “BlockAll” > Delay > “BlockAllDynamic” my physics are simulated normally.

There might be something to do with the collision type, I am still debugging to try and pinpoint the issue.

Maybe I am misunderstanding something, but why are you changing between collision profiles in the construction script? Logic there needs to be set up once when you place your actor instance inside the level and it runs only once when the actor is spawned(or right before that rather). So if you play in editor the collision profile should be set to whichever one your bool dictates. If you want to change the collision profile in the editor, you’ll have to do it manually.

If you want to dynamically change collision profiles at runtime you should do it in the event graph.

Do tell me if I am missong the point and I’ll think about it some more.

Hello and thank you for your input in both posts.

It’s pretty simple: this is for a tool for Level Artists; a semi-procedural terrain BP which covers an area with a variable number of Static Mesh Components. Collision affects Foliage painting, so this needs to be all settled in Construction Script.

I mean I guess I could enable collision just so that Foliage painting works in Editor, and then push the exact Collision Profile that we need for runtime on BeginPlay (depending on the paramter value that Artists set in a given Actor). Even without that we somehow managed to get this to work for us, but still I feel like there is a bug and the nodes should work just within Construction Script.

PS. I described my requirements for this tool in this forum post, although now that I read it again, my description might be a bit confising… Procedural plane - vertex color & foliage painting - Content Creation - Unreal Engine Forums

So after debugging and reading a ton of threads I figured out what was causing the issue. The collisiom profile node does work as intended in the event graph for my setup.

Briefly, my problem had to do with the RecreatePhysicsState() as described in this thread https://answers.unrealengine.com/questions/746127/how-to-correctly-scale-a-skeletal-mesh-physics-act.html
I scale my actor from 0.1 to 1 at runtime. The physics state is taken at a point where the actor was 0.1 scale and my forces were calibrated for that state. In my collision profile function i also switch simulate physics off and on, which updates the physics state and the same forces are now applied to a 10 fold larger object (scale 0.1 → 1)

Ok so this is for a tool, I see. You want to have the collision setting controlled from outside the static mesh settings panel?

Indeed, intuitively, your approach should work. Have you tried creating an enum and using the switch on enum node?

Solution for newcomers, if you have to change all of these:

  • Profile
  • Collision type
  • Mobility
  • Optional: Set physics is needed
EquipmentMesh->SetCollisionProfileName(FName("Ragdoll"), true);
EquipmentMesh->SetCollisionObjectType(ECC_WorldDynamic);
EquipmentMesh->SetMobility(EComponentMobility::Movable);
EquipmentMesh->SetSimulatePhysics(true);

This is for Staticmesh (Manually)
If you work with static mesh and they do not have collision you have to add it manually. UE5 does not yet have support to create dynamically (not at least that I know of) something similar.

To add it you have to go to the specific piece and in the static mesh panel:


This is for DynamicMeshComponent (Automatic)
Geometry Script Users Guide | Unreal Engine 5.1 Documentation


You have to be careful if Blueprint was compiled after having placed the n objects it will not work, for some reason I don’t know related to the profileName. Therefore, you will have to replace them one by one (If this is not your case, then lucky you)
Collision Response Reference in Unreal Engine | Unreal Engine 5.3 Documentation

Furthermore, a good practice would be not to leave anything in plain text. You can create an Enum and take the value you need. This way you ensure that you will never make a mistake.

This node still does not work as intended.
I am storing static mesh actor references and their collision profiles in a map. I can see the map in the level, populated correctly, with the profile names the actors had.
Then I set their collision profiles to “No collision” and then I try to apply the collision profiles stored in the map back to the respective static mesh actors. the result is that the actors remain collisionless.

I am even supplying the collision profile name in the form of the struct it is supposed to be in. This still doesn’t work.

EDIT: Turns out you can’t just compile an editor utility, you need to rerun it for the changes to take effect.