Check if tile is occupied


#1

Hi I am a bit confused how to check if a tile is occupied. Is there a simple way to check if there is a link between objects? I am trying to instantiate different things to tiles but I want to make sure there’s not a player or object already on these tiles. I was hoping I could use OnNodeCostCallback but I can’t figure out how to use that as the callback when I use IncludeCentralNode.

validBuildNodes = map.NodesAround<SceneMapTile>(movementSelector.tile, false, true, null);

I can’t fiigure out how to use callbacks properly, I tried using OnNodeCostCallback in place of null but it isn’t allowed. It seems you can only use OnNodeCostCallback when you specificy an radius? I was trying to check the central node which is the index of 0 in the list but I can’t use OnNodeCostCallback this way so it won’t check if its valid or not, any thoughts would be truly helpful, thank you!


(Leslie Young) #2

You have to keep track of this yourself. Have a look at Sample4Tile.cs and note the unit property. This indicates what unit is currently on that tile and that can then be used during the OnNodeCostCallback call as seen in Sample4Controller.cs line 190. Line 166 shows how I use this callback.

An example of how I link/unlink with nodes can be see in Sample4Unit.cs line 40 LinkWithTile. Have a look at the code making calls to this, which is mainly when a unit moved.

You can similarly add all kinds of other things to track in your custom tile class, like how Sample4Tile has tileName and tileObj fields too.

Tip: If you are using Visual Studio then click on a function and then press Shift+F12 to get a list of areas a funtion is used. This is very useful when trying to learn from code.


#3

Cool thank you Leslie, and thanks for the cool visual studio tip!