RTS game pathfinding

Yeah but the performance got worse after every hotreload, because there was many instances of BatchedEvents running at the same time. Because the jobs are in a static list I think their execution might get duplicated?
Here’s my video proof of what is happening. (Sorry for the beeping sound, accidentally my timer got recorded)

I can’t pinpoint thought what is wrong on your code, because the find object of type should find the existing instance. Might be even some unity bug :thinking:

Soon as I posted this I realized what could be the cause, and I think I got it!
FindObjectType wont find anything things has HideFlags.DontSave!
I tested commeting out the HideFlags and your code worked. So bit of a curve ball from unity :rofl:

Yep. But it’s fixed in my dev version now.

Yeah cool, I got it also fixed on mine.

Hello - I’m very interested in the RTS example, and think this system would be great for my game. However, I am having difficulty working out which version of the A* Beta to use with which version of Unity to get the best (and most stable) version of the RTS system.

I have tried the latest Beta (4.3.36) and Unity 2019.4, and it seems to work, but there is a warning that the burstified recast code is only supported in Unity 2020.1, and that it is falling back on slower pure C# code.

However, if I use the same Beta version (4.3.36) in Unity 2020.1 I can select units, but they do not move to anywhere I click the mouse. There are also a few errors - I have uploaded a screen shot.

Also I can’t seem to get any waves of enemy AI, which appear in your YouTube video - is there a way to activate them?

Thank you for your help. I’d love to get this working in my game as it looks great, and the A* Project in general is amazing.

Hey guys,

We are planning on using A* Pathfinding for our RTS game. Currently we’re using Unity’s NavMesh but it is not ideal for the number of units we’ll have on the map at any given time, particularly in the later stages of a match.

We were wondering if there was any plan to include the current elements of the beta into a production version? The latest update to the actual package itself being from March 2020.

yeah i get those native collection leak things in our project as well
@aron_granberg any idea what this could mean?

most likely @aron_granberg gave up on it :rofl:

Unitys burst and collection packages are still in beta. I cannot include those in the stable version until unity brings them out of beta I’m afraid.

During the past year I think I’ve tried to update our pathfinding asset 3 times to last years march version and it’s literally impossible to get the assemlby definition things right. I think I must have spent 12 hours total trying to do it.

Should have forked the project in the very beginning to my own hosted repo. Definately do this if you plan to use this.

Also after updating to the project to use HDRP graphics pipeline I started getting errors regarding on gizmos drawing. I would be nice if you could try to reproduce this. @aron_granberg

I deleted the beta branch from the project and replaced it with the main branch of the pathfinding pro.
Now works without errors, without undebuggable memory leaking burst compiler code. At this point I don’t know if I should be sad for the time lost not doing this or glad for the lessons learned.

Would it be possible for you to post (in a new thread) the exact version of HDRP you are using along with screenshots of your settings? I’ve seen some HDRP bugs before and most have boiled down to some specific HDRP setting or a breaking change in a some HDRP version.

Hi Aron, thanks for the prompt reply.

I see the Burst package was verified in Unity 2019 LTS. Hopefully the Collections, Hybrid Renderer and Jobs packages can get there with Unity 2020 LTS when it comes out in Spring 2021.

Hello,

I ended up giving the Pro version a try: I downloaded the latest beta yesterday and I started converting my game from Unity’s NavMesh to Recast Graph + Local Avoidance using Example 18 as a guide.

This is what Cradle of Chaos does currently (with Unity’s NavMesh):

  • Agent enabled for pathfinding when looking for enemies to attack
  • Agent disabled/Obstacle enabled when a unit is attacking (they are always stopped when they attack)
  • Units cannot overlap with either friendly units or the opponents’ units

I’m looking to replicate this but with Local Avoidance. When I add RVO Controllers to all units I get the behavior from the below video so I think I need to check whether there is a path from each unit to its top target in my FSM “Chase Target” state.

But still, on the video I think there’s so few units that they all should find a path to their respective targets instead of half turning around and getting stuck like that. Am I missing anything here?

Update: I have now integrated a bit of code to check whether there is a valid path between the unit and its potential targets however performance gets hit massively (10ms/frame additional):

I’m using something along those lines:
PathUtilities.IsPathPossible(AstarPath.active.GetNearest(tr.position).node,
AstarPath.active.GetNearest(enemy.tr.position).node))

I also think that it is possible that the RichAI shape I have defined around my characters is too wide and as a result the melee attack range is not high enough anymore (it was suggested to take some room around the characters for AI shapes in one of Aron’s tutorials I believe). I’ll either make those shapes tighter or increase the melee attack range a bit.

What would be the the most performant way to look around the characters for enemies that are actually reachable using the A* Pathfinding Project?

Hi

@nico_st_29 What I see in that video is that most agents have an enemy adjacent to them, so they could attack them. This is what most RTS games do: when they can attack an enemy, they do so. This is partly to avoid all the problems with having each agent try to find a path to a specific other agent as this will get really complicated with crowds of even moderate sizes.

1 Like

Hi Aron,

Thanks for getting back to me on this. Essentially this aggro thing is at the center of the game’s mechanics. This was working fine with Unity’s NavMesh but I wanted to be able to use RVO “SC2-style” as you say, making units belonging to the same faction give way to the ones who need to move.

If I sum up my questions:

  1. What is the best function to use to find the nearest neighbors in a specified area?
    I saw that in another post you replied with a way of getting the KNNs
    Using RVOQuadtree to find neighbors of Agent

Using this properly would save some perf in my system as I wouldn’t have to run my burst compiled KNN algo in addition to the A* Pathfinding Project code.

  1. Is there a quicker way to check whether there is a valid path between 2 nodes than PathUtilities.IsPathPossible()?
    The code I was using for testing can be optimized, e.g. I can have each unit store its nearest node instead of using AstarPath.active.GetNearest() each time. I’ll try it tonight but I feel like it’s still going to be slow.

  2. What is the purpose of using RVO.locked? Should I use it as well? What does it do actually?

Update:

I went back to Example 18 and tried something to see for myself what the actual behavior is here:

So I think my only question (the rest I can figure out for myself with the docs and going through the code) is: is there a way to have the melee agents actually ‘push’ the range units currently attacking so that they can get to the enemy units?

I’m guessing this would require rvo.locked to not be used but how?

Thanks a lot