How to prevent actors from spawning in inaccessible areas?

So the player can remove items from the inventory. And the items will spawn in the world, close to the player. Some of these items are vital for the player to progress.
What if the item falls into a big hole, or it spawns behind a wall, where the player can’t reach? Are there any tried and true methods to prevent that?
Thanks.

Simplest thing you can do is to make a linetrace or boxtrace from the players camera forward. Then based what it hits and where for example:

  • if it hits ground and it has space spawn
  • if its too close or it doesn’t have space pick different spot you hit and keep checking
  • if there is no space just print a message that there is no spot to drop an item

Also if you have nav mesh generated everywhere you can query it for closest walkable location near player.

And when spawning an item there are actor spawn parameters that can adjust you the location of spawn if it would be colliding with something.

For vital items i would consider blocking ability to drop it entirely but depending on your game design and structure you might want to handle it in some way.

Hopefully this answers your question

2 Likes

I think the safest thing to do is to use an Environment Query System that looks at all the options you want.

1 Like

Thanks.
But how would you check for space?

That means I would have to assign AI to all the items in the game, right? Is that efficient?

The character capsule component should prevent you from getting into too iffy of a place. The interact collision of the item should be centralized to the actor and mesh and large enough to cover most of the item. With all of these setup I trace from pelvis down for the spawn location. Haven’t run into an issue where I can’t pickup the item again.

Other option is to have UI interaction. Multi-Sphere trace around the player (1.5m from knee height) and list all hit pickup items in the UI. Then click and drag to pickup.

1 Like

EQS are AI-independent and can be used in any blueprint.
They simply generate a grid of points around any location you want or search for actors by class and tag, and then you can discard and score each one.
For example, here I use it to spawn enemies only in places the player can’t see or behind them, that have valid paths and aren’t near walls(space check).

You can also check the result in case it doesn’t find any points.

1 Like

I was using the item mesh itself for the interact collision. Do you mean you can have a separate component for that? And if so, what?

I’m trying to spawn the items in front of the player, mid air, and maybe give them a little push so they go down in an arc. They will have physics enabled. I’m not spawning them straight on the floor. Is a trace safe enough for that to ensure they don’t end up in an unreachable spot?

Thanks, can you share the Environment Query graph?

I use collision components (Box, Sphere, Capsule). The Mesh collision is disabled.

No. You need to do a robust sweep, possibly even use predict projectile path (advanced)

1 Like

You can fetch that data from mesh collision, have another component act as simpler collider, like @Rev0verDrive already mentioned or use bounds.

So for example if player is too close to wall either spawn it inside the player, behind him or prevent spawning it at all and display some message. If minimum distance is kept you can spawn the item in front of the camera and attach it to the player. For it to not going through the wall use CCD (continuous collision detection)

1 Like

But how do you simulate physics if the collision is disabled?