#Ai Pathfinding Issues In Lobby And Worlds

82 messages · Page 1 of 1 (latest)

low gyro
#

Hello. we're having trouble getting our Ai pathfinding system going. We're using the A* Pathfinding Pro , and as @oak root suggested, Its great, except we cant seem to be able to make it work server side. Its worth noting that we've built our lobby system using the lobby and worlds package, which needs us to simulate physics from the game scene for some things to work. Hopefully that's relevant. The pathfinding works on the client side but never on the server. Here's the function that spawns and passes in the array of path targets.

[Server]
public void SpawnAiMinions(float _spawnDelay, NetworkConnection _conn)
{
    GameObject _ai = Instantiate(_aiPrefab, _aiSpawnPoint, Quaternion.identity);
    SceneLookupData sld = SceneLookupData.CreateData(gameObject.scene.handle);
    UnitySceneManager.MoveGameObjectToScene(_ai, gameObject.scene);
    InstanceFinder.ServerManager.Spawn(_ai, _conn);
    _ai.GetComponent<MeowAI>().FindAiPath(_conn,_aiDestinations);     
}```
The FindAiPath function being called looks like this.
```[TargetRpc]
  public void FindAiPath(NetworkConnection _conn, Vector3[] _pos)
  {
      if (base.IsOwner)
          _seeker.StartMultiTargetPath(transform.position, _pos, true, OnPathComplete);
  }

  [Client]
  public void OnPathComplete(Path p)
  {
      if (p.error)
      {
        Debug.Log("path returned an error: " + p.errorLog);
        return;
      }
      MultiTargetPath mp = p as MultiTargetPath;

      if (mp == null)
          return;
      else
            path = mp;
 }

This obviously requires us to have an owner control the movement. It works. We tried the following code but cant find any nodes server side on pathcomplete. Any ideas on how to fix this ?

 public void FindAiPath(Vector3[] _pos) =>_seeker.StartMultiTargetPath(transform.position, _pos, true, OnPathComplete);

@real epoch

hasty pond
#

Any suggestions to get A* pathfinding to work with stacked scenes and simulated physics would be super helpful 😭😭😭

night estuary
#

Any errors, logs, symptoms?

low gyro
# night estuary Any errors, logs, symptoms?

After spawning the Ai over the network, when we attempt to use the seeker component to start a path from point a to point b, OnPathComplete ,we get the log 'Couldn't find a node close to the start point' .

night estuary
#

is pathfinding built on both server and client?

#

or, is Ai pathfinding active only on server, and you get error on server?

low gyro
#

Its built both on server and client. However we can only find the path when we search for it client side.

low gyro
night estuary
#

OnPathComplete gets executed only on on Client?

#

remove the [Client] from the function

real epoch
#

@low gyroare you syncing with a NT?

low gyro
real epoch
#

and the objects that are not working are owned by the client? you're using client auth NT?

low gyro
low gyro
real epoch
#

You said OnPathComplete isn't being called right? Is that the main problem?

low gyro
#

Its being called without the [Client] attribute ontop. Im attempting to build now to see if that wasnt it.

low gyro
# low gyro

This is what I just got from trying to find a path on the server using this.

        public void AttemptPathFind(Vector3 _position) => _seeker.StartPath(transform.position, _position, OnPathComplete);```
I also removed the client connection when spawning again. OnPathComplete has no attributes at all now, its just a normal callback that can be used on both server and client also.
real epoch
#

What is the end problem though?

#

What is not working as expected?

low gyro
#

The path finding gives an error when we search on the server. We wanted to spawn the ai on the server without an owner and run the update to move the ai server side.

real epoch
#

Okay, why is it causing an error? Missing data? ect.

low gyro
#

I really really dont know. Ive spent about a week wrecking my brain

real epoch
#

You said it's throwing an error?

low gyro
#

yes

low gyro
real epoch
#

I don't know what that could be. Doesn't really show much unfortunately.

#

Is it caused by a NRE, the asset, or what? Have you tried contacting the dev of the asset to see whats causing it?

#

Im not familiar with the asset so I'm not going to be able to say why its just not working, esp when theres no obvious errors.

real epoch
#

Maybe the transform position is the same as _position?

low gyro
low gyro
real epoch
#

Validate the transform and target position. I imagine if theyre the same results will be 0

low gyro
#

Alright, I'm currently not by my desktop. I'll validate as soon as I can.

real epoch
#

Well, that was all I had. Maybe transform isn't on the ground? Id ask the author what can cause it.

real epoch
low gyro
#

Will do. Thanks @real epoch

shadow waspBOT
#

FirstGearGames received thanks.

low gyro
#

@real epoch hey, I believe I may have found out a solution to this. I made a few adjustments to the LobbyNetwork script. I changed the replaceOption line from sld.ReplaceScenes = ReplaceOption.OnlineOnly to sld.ReplaceScenes = ReplaceOtion.None and also commented out the LocalPhysics = _gameSceneConfigurations.PhysicsMode. Our AI code now works server side and scenes seem to maintain their integrity with no bugs. This also now allows us to use Physics.Raycast instead of having to simulate the game scene like we were before.

real epoch
#

Are you just disabling scene stacking? That will prevent loading as matches.

low gyro
real epoch
#

I would expect the physics to interact with each other.

#

The only way physics don't react to other physics is if they are in different physics scenes.

low gyro
#

Hey @real epoch , We're at that bridge we've been procrastinating crossing over. To recap on our issue, we're using the Lobby and World implementation to get games started, and when we set the loadPhysics option to none, the AI in our game is able to use the Pathfinding package serverside. The issue is now as we feared, the scene physics are interacting with each other. When setting the loadyPhysics mode to none, the Astar Pathinder wont work. The Ai will stay in place and no path will be drawn server side, however the AI instance on the client side is able to find a path. Kinda stuck on what to do, any ideas?

#

This is with loadPhysics set to 3D like we want, but the pathfinder wont work if the physics is set to that.

brisk pecan
#

Are you simulating the PhysicsScene on server when stacking scenes? Just something I have missed before. Could explain why the client code is working but not the server (multiple physics at the same time).

low gyro
#

Can you explain a bit more on the question. I am simulating physics on projectiles to detect environmental contact, player and ai damage use OnTriggerEnter. Thats the only physicsScene simulation happening at the moment. How would I simulate the PhysicsScene for the entire scene (which is what I think I'm understanding from your suggestion) ? @brisk pecan

stoic pivot
# low gyro Can you explain a bit more on the question. I am simulating physics on projectil...
Unity Learn

Previously, Unity had one physics Scene that was populated with all the bodies and colliders from all of your Unity Scenes. Starting in Unity 2018 LTS, you can split physics across Scenes. In this tutorial, you'll learn the basics of creating and loading alternate physics Scenes that can overlay a main scene.

Scene Stacking is the ability for server or host to load multiple instances of a scene at once, usually with different clients/observers in each scene.

low gyro
#

Cool,Thanks @stoic pivot

brisk pecan
#

Thanks @stoic pivot

low gyro
#

@stoic pivot sadly the simulation doesnt affect the Astart Pathfinding. I created the PhysicsSceneSync script as needed and debugged OnPrePhysicsSimulation to see if the sim is happening, which it is but the AI still doesnt work as long as we are using Local Physics mode to 3D or 2D. I'm outta idea

rare bluff
#

How to solve it? Doesn't anyone use a* pathfinding for lobbies?

stoic pivot
#

I think @gentle niche uses it. Oh, I'm not sure if he's used it in the lobby system though

gentle niche
#

@rare bluff You can use a lobby scene. Best bet is to go to the A* discord and ask how to create separate graphs for the lobby. https://discord.gg/qKN2AC7s3x

On the Fish side, there's nothing special that needs to be done. You can create lobby player objects and assign ownership of those objects to players in the lobby. Then when a match/game starts, create the new player object, assign ownership, and destroy/despawn the lobby object.

rare bluff
gentle niche
rare bluff
gentle niche
#

@rare bluff The scene conditions isolate the objects to only get data they should get. So, you could have 1000 players with 1 player in a specific scene and that 1 player would get only the data for that 1 client.

gentle niche
#

Make sure you read up on the scene stacking. It's a little confusing but it allows you to have as many of the same scene as you want for matches. Each one will have its own physics and everything like it's a new game.

rare bluff
gentle niche
#

@rare bluff It's pretty convoluted but doable. You can use the layers in A* to create the avoidance per stacked scene. The default layers count is 32 but you can extend it to as many as you need. A* sits on top of the scenes. So, you can have the singleton manager in a scene that runs all the nav. In the screenshot, you can see I have the 1 manager in the inactive scene and the objects in the active scene move. (green line)

#

Tags are helpful as well.

#

You can also so Nth number of independent graphs that you can save and load.

rare bluff
gentle niche
rare bluff
#

As long as these lines are used to make the grid, a* will not work for grid graphs and similar ones (in stacked scenes). I overloaded a*'s methods so that it calls scene physics, and now everything works. I create a new grid for each new room, and immediately start the scan by passing a*'s singleton a reference to the physics scene.

low gyro
#

Awesome ✌🏽 , this gives me a chance to circle back to A* again. Thanks @rare bluff

teal horizon
#

im gonna look into doing this as well, seems like exactly what I need

teal horizon
#

so just to be clear the server is running a physics scene globally and you are calling the Scan in that scene?

#

just trying to wrap my head around how to overload these methods @rare bluff

#

any help would be really appreciated!

teal horizon
#

I think I got the overloads working in the A*Path script, how are you doing the layers @gentle niche ?

gentle niche
#

@teal horizon You mean stacked graphs for multiple levels of height? Pro has a specific grid graph for layered. Or if you don't have pro, you can use the tags and multiple grid graphs and tell the seeker to avoid tags per object. Each graph has tags instead of using colliders and it makes the object move around per graph. It's a little confusing to do it that way though. You can stack 16 graphs on top of each other but can extend it to 256 with a change of the code. There's no major performance loss for extending it if needed.

teal horizon
#

this will be with the a* plugin in the global scene like youve set it up in your screenshot above

teal horizon
#

eureka! not I've got the a* instance generating a graph for each stacked scene's individual physics scene, assigning the agents on that graph to that graph alone, and then removing that graph when the scene is unloaded. thanks @rare bluff and @gentle niche for the bump in the right direction, and sorry for necroing this thread 😅

gentle niche
#

@teal horizon Would you mind making a little guide for how you did it and sharing it in the #community-resources channel? Nothing elaborate or anyting. Just a few screenshot and how-to instruction. That's something that a lot of people would really enjoy having in their project but it's a tough concept for a lot of people to run nav across multiple stacked scenes.

teal horizon
#

I'll see if I cant make a devlog or something when I actually get it working 100%, I'm still running into some issues with the AI behaviour when multiple of the same scene type/name are running, gonna try messing around with the scene handles for splitting the AI properly