FindObjectsByType in RecastGraph Update

Hi there !!
I’m facing some problems updating my RecastGraph, after seeing the profiler i just found that you are getting all the colliders in the scene via var colls = MonoBehaviour.FindObjectsOfType(typeof(Collider)) as Collider[];

Since my project is getting bigger this function is not really something viable. Is there some workaround to update the graph without getting all the colliders in the scene?

Thanks!!

PS: My current version is 3.8.2

Hi

You can add a RecastMeshObj (with dynamic=false) component to all objects that you want to include in the scan and then disable ‘Rasterize Colliders’ and ‘Rasterize Meshes’. The RecastMeshObj components are stored in an optimized lookup tree and it will be much faster to find them during runtime.

Hi Aron thanks for the response, I will try to implement it!!

Thanks again

Hi Aron, the above solution worked for the problem I had, unfortunately right now i’m digging in a deep rabbit hole in my project, facing one problem after another so I’m going to explain what I want to accomplish so you can help me better:

In my game the player will be navigating through the ocean from one island to another, so, in each Island there will be animals that will have AI walking on them. Here it is a little screen so you would have a better understanding :slight_smile:

There are two cases when I have to update the graph:

Case 1 Docking in a new island:

The player would be navigating, the when he reaches the “Dock” I will calculate the new bounds of the graph, based on the player position etc…

In that moment I can do a trasition, fading the scen to black, there I Update the graph via:

var guo = new GraphUpdateObject(new Bounds(Singleton.Instance.CharacterController.transform.position,bound_island)); guo.updatePhysics = true; AstarPath.active.UpdateGraphs(guo);

The problem I’m having there is that even I’ve updated the bounds of the graph it won’t create new connections out of the previous graph calculated in the previous bound.

Even I have this moment of transition when I can call your function of “Scan” sometimes it will take around 5-10 seconds to recalculate all the new island so is not viable to do it that way.

Case 2 Walking From One Island to another:

The player walks through the bridge I detect is a new island and Update according to the bounds of the new island, the problem here is that I don’t have any kind of trasition to ReScan the whole island. Here I have the same problem, I can Update the graph with the new Bounds, but is not going to add new connections or tiles to the graph.

Here I have some screenshots so you can tell me if I’m doing something wrong.

Maybe is a problem too general, not really related only with the code more about how to create a valid WorkFlow , so maybe if you can give me some ideas.

I have been reading a lot of stuff in the forum but I couldn’t find any solution. We are working on the Pro version and the current version that we are is 3.8.2

Thanks again for the support I hope we find a solution togheter :slight_smile:

Hi

Are you sure you want to use a recast graph for this?
Your islands do not look that complex, and the surface seems pretty regular, so I would suggest a grid graph instead.

Hi Aron, thanks for responding.

I just changed my graph to be a grid graph, and it’s working really neat, much faster !. But I’m still having the problem that I can’t just update the graph, I’m getting this warning:

The Grid Graph is not scanned, cannot update area

Is there some step that maybe I’m skipping or something like that?

Thanks again :slight_smile:

Hi

Maybe you have tried to change the width or depth field?
If you do that you cannot do a normal graph update, you must scan the graph.

AstarPath.active.Scan();

Also if you are setting the width/depth fields, make sure to call gridGraph.UpdateSizeFromWidthDepth as well as the width/depth values are derived from the unclampedSize field.

Ok Aron, yes I’m changing the size and depth and also calling the UpdtaeSize function, so I just have to call the Scan function. It seems to work really fast on build so I don’t think that is going to be a problem to Scan the whole Island on runtime.

Thanks again Aron !.

1 Like