Weird collision request

I have a player character that can place objects at their current location. That object has collision enabled and configured correctly, it should in most cases block the player and always should block other players and AI.

However while standing in/on it, and until the player leaves, the player themselves should not collide with the object.

Step by Step:

  • Player places object at their current position
  • The player that placed the object is still free to move around
  • Other players and AI are blocked by object
  • Player moves around a little bit but does not leave the collider volume
  • Player is still free to move around
  • Player finally exits the collider volume - Here’s where I’d assume I hook in, MyObject::EventActorEndOverlap(AActor OtherActor) <- (Guessing at the signature, I’m working in blueprints.)
  • Player can no longer walk back into their placed object.

How can I selectively ignore one single actor’s collisions, but only until the first time they stop overlapping?

you could use tags

I can use tags to mark what I should and shouldn’t collide with, but that’s not what I’m struggling with.

Let’s boil this down to one placed object and one player. Nothing more in the scene except the floor they’re assumed to be standing on.

1.) The player is standing idle.
2.) The player places their object.
3.) The player and object are now overlapping. If we stop here the player loses control of their character until the object is removed.
4.) We disable collision on the object. The player now has freedom of movement again and can exit the object as they normally would.
5.) The player leaves the object. If we stop here the player can just walk right back into their placed object.
6.) We enable collision on the object. The player can now no longer move back into the object they placed.

That’s all great. That’s what we want. But now let’s make it more complicated. Two players are going to place one object each, directly adjacent to one another. Both players are instances of the same class, which extends from Character.

1.) Player 1 is standing idle.
2.) Player 2 is standing idle, directly next to Player 1.
3.) Player 1 places object 1.
4.) Player 2 places object 2.
5.) We disable collision on object 1. Player 1 has freedom of movement.
6.) We disable collision on object 2. Player 2 has freedom of movement.
7.) Player 1 moves away from Player 2, just within the bounds of their object so it can’t have collision enabled yet.
8.) Player 2 moves toward Player 1.
9.) Player 1 is halfway inside object 1.
10.) Player 2 is halfway inside object 1 and halfway inside object 2. This is an invalid state.
11.) Player 1 moves away from Player 2. They have now left the bounds of object 1.
12.) Player 2 moves toward Player 1. They have now left the bounds of object 2 and are fully within the bounds of object 1.
BRANCH :
13 A.) We enable collision on object 1. Player 2 loses freedom of movement. This is a game breaking invalid state.
13 B.) We leave collision off on object 1 until Player 2 (And any players that enter in the meantime) has left the bounds of object 1. In my limited testing this is a frustrating invalid state, as players expect to be able to wall off other players in this manner.

What’s the magic that I can do before step 10 in order to prevent that initial invalid state? In theory I just need to be able to disable collision only for the owning player. I just don’t know how to do that given a tag or other marker value on either the object or the player.

The easy solution to this exact problem is to not let players place the objects inside of themselves, and instead have players place objects directly in front of/behind them. However with my (again limited) testing players find this simply to be less fun and more frustrating, as it is a fast paced game leaving little time for accurate placement of these objects. I’ll continue to experiment with controls that might allow for avoiding this problem in the first place, but it seriously looks like this is the most fun control setup for this game.

PrimitiveComponent supports this: look at the IgnoreActorWhenMoving() function. You give it an actor and whether you want to ignore them or not when moving. You’d want to set this up on your collision capsule.

Thank you, that helps a lot!

Unfortunately it’s only half of what I need, I still need to be able to detect when the player leaves the object’s bounds in order to turn collisions back on. This method seems to do what it says, and ignore the given actor, but I need to be able to still overlap the actor to determine when they’ve left the object.

First off going to try adding a primitive to my object Blueprint with a similar collision setup as the mesh, but set to overlap the player instead. We’ll see if that can do what I need.

If that fails I’ll try just checking every tick to see if collisions are being ignored, and if so implement my own bounds checking, but I don’t like doing that with a physics library available.

EDIT: Of course the first one didn’t work, I’m setting the character to ignore an actor rather than the mesh component, so adding more overlapping components won’t help.

You should be able to ignore the actor with the root collision capsule, and that will only make that capsule ignore the collision. If you have another component set to overlap you should continue to receive the overlaps, because the ignore list is stored per-component. So in that case when you end overlaps with that sub-component, you can then remove the ignored actor from the root capsule.

I think what you proposed was adding something to the overlapped object, I am proposing something on the player.

I had done the disabling through the player but was trying to re-enable through the object. :\

Thanks for the help, I’m now exactly where I want to be with this mechanic!