A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Assets and Asset Store' started by Leslie-Young, Jun 2, 2012.
I can't see why not. There is nothing in the package that needs pro.
In the next update
and some other stuff.
can you pass the starting node for the following function? It would be more flexible to calculate some stuff that depends on the starting node.
this._ShowNeighboursRecursive(radius, true, validNodesLayer, checkMoveMod, checkOnOffSwitch, this);
Submitting update 2.5
Moved the TMNController and unit layer related code to samples since it is more related to sample code than the core of Map&Nav. Added requested sample (6) which shows how to spawn a unit when you click on a tile. Added a new tool to help setup the links between nodes by breaking links between nodes where the one node (tile) might be much higher than another and you do not want units to move from the one node to the other in these cases. Added a way to links up the nodes between different maps (MapNavs).
This looks great. How many nodes can you have before you start running into serious performance issues?
It is best for where you want 50x50 or less tiles per map. Do not get it if you want to make something with 100x100+ tiles, the creation and init times are just too much.
I'm actually testing a 200x200 map and the creation time is a few seconds and when you hit play it takes around a second+ to just init, and it makes it editor slow. I'm might have to look at a different solution for my own game as I need a pretty big grid for it.
Is that number smaller when working with android and IOS ?
Just brought the asset, lets see what I can come up with ( I'm going to try and use playmaker too ...)
Hi ! Pretty neat package i must say (just bought it, hoping it'll gives me more motivation to start working on my game). I just noticed one or two details (this post is 2.5 compliant)
I've tested the samples a bit, toying with the number of moves possible for a given units, raising it to 8. And then, tiles activation takes a lot of time (the editor just freeze for a lot of time - like 2-4 seconds, depending on the number of tiles concerned). I cant profile since i'm on indie, but i guess the functions responsible for showing/hiding the hex/squares for movement could be handled differently. I'll let you know if i can find something to tackle this huge perf hit.
After a little Stopwatch benchmarking, if i set the max moves to 8, it takes 1470 ms to activate the grid, and 870 ms to deactivate it.
And i've noted that land units now have sort of an annoying "head bobbing" syndrome while passing through a tile. Like they were stopping and going on again.
Thanks for pointing it out, I'll have a look at what is going on there.
 for "head bobbing", turn off "Tilt to Path" if you are using the two options below it. You can also go to NaviUnit.cs line 377 and comment out the pos.y += 0.01f;, it should not be there and will be removed for the next update. If you do that then "Tilt to Path" being ticked won't matter. but I still recommend turning it off if you are gonna use adjustToCollider and adjustNormals.
 I was doing something stupid in the function that was showing the nodes, which made it slow after 3 radius tiles. It is fixed now and will be in the next update which I'll submit now (version 2.6).
I dont know how safe it is to discuss your implementations here, so i wont post any code, but i was wondering why you dont do it based on abstract coordinates (which are used to generates the nodes if i'm not mistaken). A simple matrix approach could speed it up on a first pass.
Also, i was thinking about the skipList, which could be hold by the start node and passed as a ref to each recursive call, so you dont have to recreate it each time you check a node (just a guess, i'm still trying to wrap my head around your code).
All in all, great lib and thanks for the great support too.
Like I said in previous post, I was being stupid there but I've now fixed that recursive function
Is it possible to make the grids smaller, like 1/4 the size they are now, and then have a unit take up more than 1 space?
I will be buying this in the near future when I start my TBS game i've always dreamed of. This seems perfect!
I agree with seanP though, having units take up more grids would be a cool feature
Also, I think you need to work on the speed. If 70x70 is unplayable, 50x50 won't be ideal either. Supporting larger maps would also give you more customers, and I don't see why that's to big with some good optimization.
Very cool assert though, thanks
I got it working with playmaker pretty easily by following the instructions here: https://hutonggames.fogbugz.com/default.asp?W329
Basically add "
" to the top of the script, create this variable:
public PlayMakerFSM behavior;
and drag the playmaker FSM into it (you can drag it right from the inspector to the inspector).
Then using one of these "templates" in the script where you wish to update playmaker (for example on the sample weapon script in the "OnFXMissileReachedTarget" behavior)
FsmFloat test = behavior.FsmVariables.GetFsmFloat("test");
This gets the variable named "test" from the playmaker FSM
test.Value = 0.666f;
This sets a variable ("test") in the Plamaker FSM Just change "test" to your variable name and use the different types (int, string, etc.)
This sends an event (change "event" to the event you want to send)
I am also working on AI with playmaker. PM me if you're interested in figuring this out together. So far all I have done is made a model play a walk and idle animation but I am likely to redo it since I did it before I figured all this other out and used a sloppy method of Get Pos for x and z and checked if x or z was changing and played animations based on that. It works but I think I can do better... I just have to figure out where in the code the move happens. So far all the places I thought it was had no effect.
i bought your asset 2 week ago and i tryed it a little just after and it worked, i was able to generate a tile map.
did not touch it until today, i updated it and i can't get it to generate a tile map.
i set the layer like the .pdf said, then try creating a MapNav in an empty scene. I set Tile layer as "Tile" but there is no Unit layer select box like in the video tutorial. Then when i click create it add a MapNav in the hierarchy, but there is no node in it.
i tried setting TileNode Prefab as one of your prefab but then it create the MapNav, add one node in it and return an error.
tried starting with a blank project, same result.
the error :
NullReferenceException: Object reference not set to an instance of an object
MapNav.CreateTileNodes (UnityEngine.GameObject nodeFab, .MapNav map, TilesLayout layout, Single tileSpacing, Single tileSize, TileType initialMask, Int32 xCount, Int32 yCount) (at Assets/Tile Based Map and Nav/Scripts/TMN/MapNav.cs:289)
MapNavCreateWindow.CreateMapNav () (at Assets/Tile Based Map and Nav/Editor/MapNavCreateWindow.cs:76)
MapNavCreateWindow.OnGUI () (at Assets/Tile Based Map and Nav/Editor/MapNavCreateWindow.cs:57)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object parameters, System.Globalization.CultureInfo culture)
Do you have any idea what i'm doing wrong
It looks like you did not feed it a TileNode prefab, but some other prefab (from that error).
The TileNode prefabs are under Prefabs/tile_nodes => "TIleNode_Hex" and "TIleNode_Square" and "TIleNode_Square_blue"
You can also use them as template for your own TileNode prefabs. The important parts are that it should have a collider and obviously the TileNode component.
>> there is no Unit layer select box
I removed that since it is not needed any longer. Forgot to update docs.
@xyber, could you pass the root node to the function _ShowNeighboursRecursive ?
PM me about this cause I do not understand what you are asking for.
I would like to calc the movement of unit that is depended on the unit properties and the node properties.
As TNEMovementModifer is not suitable for complex case, it need to add to all tile nodes that is very time consuming. So I would rather to set it directly in code.
I plan on a hex grid of 80 X 40 for my MoM clone so it looks like I will need to wait for some optimization. I have been sidetracked with my Diablo III and Warlock research so I'm not in any rush. *grin*
the TNEMovementModifier seems have bug on the v2.6, I have set the value of Moves Modifiers to be 1 to the node indicated with blue circle. The red circle indicate the different.
Thx that worked
about the map size limit. My problem when trying to create a 100x100 map is that the editor become so slow that it's imposible to do anything. Do you think creating the map at runtime would allow to create a bigger map or that thing like moving unit would still be too slow?
also could you do a quick exemple, when you have time, on how to create a map at runtime.
@yuewah thanks, I can't beliefe that slipped through! I've fixed it for v2.7 which I will submit later today. Just want to do a bit more testing to make sure there are no further bugs related to that.
@devilwarriors The package is best suited for around50x50 or less. You could try to turn off all the gizmos for MapNav (those 3 checkboxes you see in the inspector when you select the MapNav). You can also remove [ExecuteInEditMode] MapNav.cs line 11 and see if that helps - a few things won't work then, like showing the node markers, and some of the tools of MapNav. I'll have to test and see what happens but I think this might speed things up for you.
Using the API to generate a map at runtime should be pretty simple. First you need a MapNav object, you can create an empty one, with no nodes, in the editor or create this at runtime. Then call mapnav.CreateTileNodes(...) to create a grid of say 100x100. Then call mapnav.LinkNodes() which will link the nodes up. Telling which nodes are for water, or land, or anything else than the default you specified is another matter however; but even this can be done at runtime and you can have a look at the MapNavEditor.cs script to see tools (the ones you see in inspector) are done. Maybe have a 'loading' indicator while all this is happening as it could take a second or few.
 I did a litle test. 100x100, with only "Gizmo Draw Nodes" on and the other two gizmo options off and it is pretty fast. Drawing the links adds the most strain. My development PC is petty decent though, so your experience may be different.
Removing [ExecuteInEditMode] won't matter too much. One thing you will notice when you remove it is that the node links might not show up even if the gizmo for them is turned on. This is because the nodes might not be linked (something which happens at runtime). Some tools does the linking if they need the nodes in that state to function.
Thought I'd capture a vid of me testing a 100x100 grid, so you can see what kind of performance you can expect. I think anything up from this will really be pushing it so I'm gonna stick to, use it for a game that needs a 50x50 or lower grid.
Also remember that things will get slower at runtime depending on your art and how you present the world. For example making a 100x100 tile world from the hextile sample might not be such a good idea, depending on the optimizations you can apply and the camera angles used.
My machine spec, i5-2500K, 16Gb, HD5870
When you release updates, will you comment the changes in the code? I have made a lot of changes to the code and don't want to overwrite it so I'd like to be able to just update it manually based on your changes.
Also, I noticed that when an enemy unit is straight out from the attacking unit, it gains +1 to the range (i.e. I can click on an enemy unit just outside the range marker and it still attacks them). It doesn't happen when the target is on a corner just outside of range..
I can't reproduce that. With which marker type and grid type are you using? You can't mix for example 40neighbour grid with a 8-neighbour marker.
It's not happening for me now either. Strange. Maybe it was because I was using the dungeon example to test my combat system and that one isn't properly set up for it? In any case, it doesn't happen on the first example which is what I've started to use now. Since I'm messing around with the spawning code and have manually set the tiles in the code, I can't go back to the dungeon example to see if it is still happening. I'll go back to that when I have my code finalized and suitable to use on different sized maps.
ye, the 1st one is the only one properly set-up for sampling combat. The dungeon sample do not even have a radius maker, which the combat related sample code needs. It was just a sample of doing a basic dungeon type thing and how one might do a door with the nw components that "modify" node links at runtime.
I've mentioned this in PM and I'll mention it here. You guys should NOT be building games on my sample scripts. They are there to show you how to use the core scripts (located in scripts/TMC). Read the code and understand what is happening there and ask me if you do not understand what I'm doing, but don't start your game's main controllers and such by building on top of the sample scripts. The sample scripts are specific to the sample scenes.
I am mostly just trying to figure out what does what. My programming skills are twenty years out of date so it's been a learning experience. I wouldn't be able to follow your examples to make my own otherwise. At this point I've managed to set it up to spawn the exact units I want and put them on opposite sides of the map. I've also set it up to easily exchange information with Playmaker as I will be doing my combat system with that (which I've started but needs a lot of work!).
Does one have to use units or can we just interact with the map itself? I guess the tile map would lend itself perfectly for some kind of board game.
Do you have any plans for making more specific unit attack types?
I saw in one of your videos that you can adjust the attack type to an extent, but what I mean for example is to have a ranged unit that can only fire in straight lines (like a rook for a square grid, or a unit on a hex grid that fires in straight lines in all 6 directions).
@c-row, yes, you can query the nodes directly. MapNav contain a list of cached nodes, and each node knows who its neighbours are. There are various functions in MapNav and TileNode to work out things like distance between nodes, or a path, etc.
@azza.g, no, I've only included units attacking each other to show how you could use the radius marker class and how you could use the tielnode functions, like the one that can calculate if another is within a certain radius of it.
yeah i only have a quad core 2.6 with 8gb of ram.. so that why
but if i understand correctly, the problem is all those vertices used in the editor to show the tiles and the connection right? In runtime since they are all invisible, it should not be a problem!?
The game I'm actually trying to do is a game like the settlers or anno. The game is made of square 4 connections tiles and you place building on the grid. Little units then go from those building to collect resources and other units move the ressouces from building to building by moving on road build to connect the building.
all i need the grid for is to know what resources are where, they're position to place building and unit on them and maybe your pathfinding code for road building. For unit movement, i could build an array of my road and save the red square position and just move unit from one square to another using a* pathfinding to found the best path. And for resources collector they will ignore the grid and just move directly on the terrain.
My problem is that this required a pretty big sized grid, i looked at the settler online and their grid is 600x600 and Anno is probably the same since they separated the map in island and the ocean don't have a grid.
Do you think you're grid system could do that? i looked at other system in the asset store and they all say the max is around 50x50 but they all use individual piece for the terrain. I plan on using the unity terrain of maybe a plane with big rock around the map so maybe that could help on performance.
sorry for all the noob question, I'm starting to learn unity and c# and I'm planing my game as i learn
this would be great with an ai pack for a computer controlled player
why ShowNeighbours() does not return closeList ? it would be helpful to find which nodes can be moved in AI controlled player.
btw, closeList seems not the actual nodes that the selected unit can move.
Like I said earlier in this thread, I would love to buy this so I don't have to build a full implementation myself. But after reading through all the comments in this thread the library seems to be very crudely put together. Not using A* for path finding, Only supporting really small grids.
And the author talking about 100 x 100 grids like something big, makes me really sad. To use it for a reasonably complex RTS, etc. you would need at least a 1024x1024 grid, or maybe even larger.
I believe that it is the visible items that cause the performance issues. If you were to only create 100 or so of them and dynamically position them when you needed them to be visible you could use just about any size grid you wanted.
Hey guys, sorry for the late reply. I got a little burnt out and decided to take a week off from deving and puters.
@devilwarriors I would not recommend this package for 600x600. I really can't guarantee that it will perform well. For my new game, which wil lsue this asset, I've changed the design so that I can work with maps of about 50x50. Still messing around with it though.
@jbarrett98121 Problem with AI is that it is dependant on your game rules. I can;t know what kinda weapon, if any, you might implement, or when or when not a unit may shoot something, and I'm not much of an AI coder.
@yuewah close list there is just a helper for that function so that it does not run recursively into nodes that has allready been "touched". Maybe what you want to do might be better with MapNav.GetPath() ?
@fholm I've never described it as a solution for an RTS. This is better suited for turn based games and board games where a grid of that size will be fine. This is not a solution for the next SIm City or Civ either. The path finder is an A* implementation, also see reply to @Sammual below.
@Sammual Yes, they are what slows down the editor if you make something big like 100x100+ and can be turned off. Yo ualso do not need to use the "markers" concept and can make tile nodes that has no renderer. For my new game I won't need markers for example (those white hex/square planes you see in the videos). I still would not recommend it for something bigger than 100x100 just cause I did not get to test that kind of sizes properly in a real game situation and can't confidently say it is a good solution for that. I just do not want to give people false hope with this package and then they have to request a refund if it does not work out.
I see, one can dream... or create another way to do it
On the topic, is there a way to change the 'tiletype' of a node while the game is playing? I know how to change it in the editor using the gui, but need to know how to change it during gameplay.
to change it at runtime ...
some_node.tileTypeMask = (TileNode.TileType.Normal | TileNode.TileType.Air);
or you can add to the current mask ...
some_node.tileTypeMask = (some_node.tileTypeMask | TileNode.TileType.Water);
Awesome, thanks heaps man
MapNav.GetPath() cannot fulfill my need, for a very simple AI unit, I want it to pick a possible move randomly, i.e. which toNode can the AI unit move to.
There is a sample of random movement. Have a look in GameController for every occurance of the "randomMovement" bool to see how this is used when that sample is on. You can see this in action when you open any of samples 1 to 5. Click on GAME_MAIN_... and in the inspector, tick "Random Movement" on.
Update() in Unit.cs might also interrest you. This is where the unit choses a new location to move to when it is not moving.
 I think I understand what you are looking for though. You want a list of all the tiles the unit could possibly move to, when a limited number of moves applies, so that you can do whatever you want with this info, like choose a random one to move to.
I did not get what you where trying to do, but if this is it, well, then it is simple To get that list you could actually use the _ShowNeighboursRecursive(...) function in TileNode.cs. The function is actually used with the internal node show/hide function but I made it public in case it was needed for something else. Notice that it takes a last variable called closeList as a ref. So simply pass it an empty list and when this function returns you will have a list filled with nodes that are in range. You wil lalso want to pass show=false so that the node markers aren't shown or you can copy this function and rip out the part that shows/hide nodes and keep the rest to fill up the list.
Note that this list will include the node that the unit is standing on and also nodes it might not be able to move to since it includes all nodes "in range". To test if the unit can move to some node that you select, be it randomly, or otherwise, you simply ignore the one he is standing on if that comes up (NaviUnit.node) and call NaviUnit.CanStandOn(...). Check out Unit.cs line 62 to see "CanStandOn" is used.
@xyber, thank for your long reply, I did what you suggested but passing a new ref instead of closeList. Just hope that you will put this feature for later version, I think it is necessary for a complete game.
I'm also considering to combine this with Playmaker, so I think if the scripts are designed to be easily integrated, it will be a plus instead of rewriting as it is troublesome to update.
I'm currently using the hex tile generation in combination with terrain. It works like a charm.
I've a question about the auto-link setup tool:
Would it be possible to integrate a "delete unlinked nodes" checkbox to it?
Due to height constraints there are nodes that do not have any link to an adjacent node. It would be cool if those could be removed automatically.
Can we get some screen shots?
Would it not be simpler to select the nodes and hit Delete? MapNav don't care if you delete a node manually.
If I understand correctly, you want in the Height Setup tool an option to specify that a node should be deleted when above a certain max height from neighbouring tiles, like how the Link-Setup tool can determine when a node is too heigh and turns off the link between the nodes?
 I can see how that wil be usefull (what I described above) and will work on an update for Monday.
 I'm submitting an update with this requested feature. There will be a button called "Delete Unlinked" under the "Link-Setup Tool" (the last tool).
I have another question for you Leslie, and other users of this fantastic package.
Is there a way to add/remove a tileTypeMask to/from a node? I have worked out how to SET it, but I was wondering if there's a way to add or remove it.
I have this atm:
node.tileTypeMask = TileNode.TileType.Normal;
But I need to have a script that adds tileTypeMask.Air to that node, so that after the script is run, the node has both Normal and Air on it. And on the flipside, have a script that removes Air from a node, effectively reverting it back to just a Normal node.