Enemies spawn inside buildings & navmesh cut zones (only in build, not in editor)

  • A* version: 5.4.6
  • Unity version: 6000.3.9

In my game, after loading in a scene and waiting 1s, I spawn enemies, using GetNearest() with a walkable constraint to try and avoid obstacles. I noticed recently that enemies can spawn inside buildings and in areas with a navmesh cut only in builds, not in the editor! Quite a surprise. How do I avoid this?

Edit: Upon further testing, for some reason, only in builds, my enemies love to run into the nearest wall they can find and stay magnetized towards it. I don’t remember it always being like this, I wonder if it’s an issue with the newer versions of unity? I’ll run some tests on older versions.

Edit 2: Tried testing earlier versions of Unity 6000.3, from the start of the year, and it also occurs there. Wonder how I messed things up this badly.

Do you mind clarifying this a bit more? Is it still seeming like this is something with Astar or something with your game in particular?

I’m guessing it’s something wrong with Astar. Using .GetNearest(), I always grab walkable points to spawn enemies in - but outside of the editor, in the build, enemies can still spawn inside non-walkable areas, or pathfind into them, causing them to run in place against their walls. I have no clue why this is happening, though.

And this only happens in builds still? Can you send over your project/a stripped down project so I can take a look and try it on my end?

1 Like

Sounds good. I’ll DM you once I upload it

The mesh you’re generating doesn’t seem to have read/write enabled and that’s what’s causing it.

I looked through the generation code, and as someone who doesn’t do mesh generation, I don’t know how you’d add it to your code- maybe just Mesh.isReadable?

OMG that fixed it!! Thank you so much! Out of curiosity, where do you see that warning? What object/class is that on?

1 Like

It was on the AstarPath component, I think nearer the bottom of it. Glad it helped! :smiley: