Using BlobAsset for Pathfinding Node Graph - good idea?

Hi there,

first, I am pretty new to the dots world, so bare with me, if I am missing fundamental principles. :slight_smile:

I have a 2D Game which is based on a tile map. Think of Prison Architect or RimWorld.
I have an Entity for every tile and for every character (besides some other stuff, but focus on the basics) I am not using any GameObjects up to now. Everything is created at runtime with EntityManager.CreateEntity

The Character Entities hold a PathComponent which holds a path in a dynamic buffer and an index to walk along the path which is gerenated by a PathFindingSystem.
That works , all is well.

The thing I dont like is, that right now, I create the node graph for my pathfinding algorythm every time the PathFindingSystem tries to find a path. I’d like to create it once and store it in a BlobAsset and store the BlobAssetReference in the PathComponent of the Characters.

There are a couple of questions that I can not answer right now:

  • Is that at all a valid Idea?
  • When a new character entity is created mid game (player buys a unit), how can I set the blobreference of this new entity to the existing blob reference? Do I take it from an other random character entity?
  • When something is build, a wall for example, I have to recreate the NodeGraph. I figured, that I have to destroy the old BlobAsset, create a new one and set the new reference on all pathcomponents. But how do I do this without interfering with potential jobs running a pathfinding on the blobasset at that moment?

There is probably more I dont understand right now, but for now, thas all :slight_smile:

Help is greatly apreciated.

Cheers
Santo.

How many node graphs do you have at once? This sounds like something you would want to write as a NativeContainer (or struct composed of NativeContainers) rather than a BlobAsset.

Hi,
well I have exactly one Graph with 10.000 nodes or more. Each node consists of of an int2 and an int, but thats subject to change and not fixed yet.

like this:

public struct TileBlobAsset {
    public int2 position;
    public int movementCost;
}

public struct TileMapBlobAsset
{
    public BlobArray<TileBlobAsset> tiles;

}

If you only have one graph, there is no reason to store it on every entity. You could make it a Blob on a singleton, or you could make it a NativeContainer.

Ok, I have to check on that. I did not stumble across NativeContainer yet.

Hmm, maybe I did not understand what BlobAssets are good for. It felt like a good idea, considering the example given in this talk

is using it in a similiar way.

But putting aside the question if it’s a good idea, I would still like to know how to do the other things. That is:

  • how to safely change a blobreference in a component to a new one
  • get the blobassetreference from somwhere to set it on a new created component

NativeContainers are things like NativeArrays, NativeLists, and NativeHashMaps.

For blobs generated at runtime, there’s not really a safe way to dispose of them. You need detailed knowledge of everything using it. And for subscenes, assigning references around can also get you into trouble.

oh, haha, yes, I did use NativeArrays and NativeLists. I imagined NativeContainers beeing something diffrent. I am getting its the general term for it :slight_smile:

for the blobassets, I think I am going to do a little bit more research on it. Thank you so far.