Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Grids Pro: A library for hex, tri, polar and rect grids [New Dcoumentation for Grids 2]

Discussion in 'Assets and Asset Store' started by Herman-Tulleken, Jul 10, 2013.

  1. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Hi,

    Again: your asset is amazing!

    I have another question, sorry and thank you in advance!

    I would like to know how can I have create a "shockwave".

    I explain : I have a grid 5x10
    I have a cell who is exploding.

    I would like to change the color of all the cell around, in the good order : the cells next to the cell who is exploding first, and after the other cells etc ... (like a ... shockwave ;) ).

    I saw your methods .getAllNeigbor... but it just give me the cell +1 row, -1 row, +1 col, -1 col.

    Thanks in advance !

    Best regards,

    AB
     
  2. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    You can get rings like this:

    Code (csharp):
    1. var ring = Grid.Where(p => p.DistanceFrom(center) == radius);
    With different values of radius you can get different rings, which you can color differently to get the showkwave effect.

    (Note this method assumes your grid is reasonably small. For much bigger grids, you will need a bit of optimisation, perhaps caching a smaller part of the grid. Let me know if you need help with this).
     
    ababab5 likes this.
  3. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Just perfect, thanks !

    I have a request :
    Game 30

    Where can I find the template?

    Thanks !!

    Best regards,

    AB
     
  4. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Glad it worked! To get the source code, send us an email so that we can send you instructions :) (support@gamelogic.co.za).
     
    ababab5 likes this.
  5. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Hi,

    Is there a way to take the "diagonal" when we ae using "path" in a rectgrid?

    Thanks!
     
  6. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Yup, you can set the NeighborSetup property on the grid builder to "Diagonals and Main" (it is on Main by default).
     
  7. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    What is the proper way to scale a grid?

    I am trying to make a 10x10 rectangular grid that is in the xz orientation for a top-down RTS game. I made an empty GameObject and attached the RectTileGridBuilder with the RectCell (SpriteCell) prefab. I rotated the x axis of the RectCell prefab's child Sprite to 90 so that it will face up in the Y axis.

    I want each cell to be 1 square meter to match Unity's 1 unit equals 1 meter. Scaling down the grid to 0.005 seems to work. Is that the proper place to scale grids?

    Also every time I rebuild the grid. The sprites jump back to the XZ orientation even though the RectCell (SpriteCell) prefab's child Sprite x is 90 degrees. To get my sprites to properly face 'up' I have to change the prefab's child Sprite x to 0 and then back to 90 again. Why?

    Also when I used the RectTileGridBuilder with the RectCell (SpriteCell) prefab, I could see the tiles. But I could not see anything when I tried substituting the RectCell prefab with the Cube (which has a missing script) and the MeshTileCell. How are these cell type properly used?
     
    Last edited: Jul 30, 2015
  8. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    I just downloaded that CustomCells.unitypackage and I get the same error:
    Assets/CustomCells/IconTiles/IconTileSet.cs(16,33): error CS0103: The name `ExampleUtils' does not exist in the current context

    NOTE: I fixed it by adding the proper namespace to IconTileSet.cs.
     
    Last edited: Jul 30, 2015
    Herman-Tulleken likes this.
  9. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    343
    i am debating which one to get..
    this or the honey hex.

    can someone please comment which one is better if you happen to have both.. or comment the possibilities with this?
    thanks!

    ie: if i wanna make a civilization game, how will this help with the implementation aside from the map building part?
     
    Last edited: Jul 30, 2015
  10. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Seems like I chose to get into Grids at the wrong time - right as support for it seems to have dried up. Well it is mid-summer and it is vacation time. I hope that's all it is.
     
  11. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    827
    In addition to the two images posted here I wanted to share the more technical details of handling the grid in my current project.

    I wanted to create a setup for a tactical turn-based game where walls would not have to occupy a whole tile but could be placed in between tiles, while at the same time not go through the hassle of setting up several independent grids, so I came up with something different.



    Every "standard" cell in my grid is surrounded by four corner and four wall cells. The grid on the above image is basically a 6x6 RectGrid for the player, but internally it gets upscaled to a 13x13 (double the original size plus one additional row/column for the last set of walls respectively) grid. How a grid point should be handled can easily be derived from its grid coordinates - two even numbers (2/2) would be a corner cell, two odd numbers (3/5) always represent a floor cell, and walls are a mix of odd and even numbers (3/4, or 4/3) whereas the combination order defines whether it's a horizontal or vertical wall.



    For movement between grid points the program first checks if the target point is unoccupied and the wall/corner inbetween is not blocked by an obstacle. One interesting possibility this adds is that a wall tile can have its own ruleset, i.e. only allowing passage from north to south, or completely blocking passage while not occupying a whole tile (like a railing for example).
     
  12. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    c-Row That is very interesting. Are you using Grids for this game?
     
  13. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    827
    I am, yes.
     
  14. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Looking through the examples I find the code extremely hard to understand. I've never seen C# code like this and I don't know if the code is just the developer's preferred way of coding or if it is very advanced and elegant coding. For me to try to understand just one line of code requires drilling into many C# source files. For example:

    map = newPointyTriMap(TriDimensions)
    .WithWindow(ExampleUtils.ScreenRect)
    .AlignMiddleCenter(grid)
    .AnchorCellMiddleCenter()
    .To3DXY();

    That requires five C# files to get the whole picture. I'm not saying this is good or bad, but is this the standard way of coding in C#? I've looked at the source code for a lot of assets and this is the first time for me to see such a long initialization string of code strung together with dot notation.
     
  15. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    827
    I usually split my code into smaller chunks but there is nothing un-C#-y about that particular segment I think. It's basically the same as

    MyVariable.ToString().Replace("x", "y").ToUpper()

    whereas each function uses the result of the previous one to work with. The one in Grids simply adds some line breaks after each function for readability.
     
  16. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Thanks c-Row. I downloaded a bunch of samples and games from the GameLogic website and lots of them won't run because of unknown namespaces, scripts missing from gameobjects. I can fix the unknown namespaces with 'using' but which scripts are missing is hard to know. I think a lot of these examples are from older revisions of this asset. But it sure isn't helping to to learn how to use Grids. For example the PathFinding sample from this page
     
  17. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    827
    Hm, that's odd. I started a fresh project and imported the current version of Grids from the Asset Store, then imported the PathFinding sample as a custom package and opened the scene in the example's folder without any warnings or errors in the log.

    Are you using Grids Pro or another version of it?
     
  18. movra

    movra

    Joined:
    Feb 16, 2013
    Posts:
    566
    That's called Fluent interfaces through Method Chaining. Explanation and rationale here: http://www.codeproject.com/Articles/640997/Fluent-interfaces-and-Method-Chaining-in-Csharp

    That style is frequently used in LINQ, created by Erik Meijer. Him being a functional programming guru should explain the syntax a bit.
     
    Last edited: Aug 2, 2015
    TokyoDan likes this.
  19. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Grids Pro. I have to try reimporting everything again. I'm using Unity 5.1.x and 4.6.x.
     
  20. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Thanks movra.
     
  21. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    I tried following the"How to set up a grid in the editor" video and do NOT get the same results.

    First, for the grid cells to actually be seen when I run it, I had to set the Grid gameobject scale to 0.01 for x and y because with everything set at 1 the cell is freaking huge.

    Second, Is Interactive seems to have no effect when I click the cell when running the demo. I'm not getting any button action at all.

    I hesitate to try anything "real" with Grids if I can't even get the first sample to work. :(

    Jay

    PS - I'm using the latest versions of Unity and Grids Pro (also tried Grids Lite; same (non) results). Also, no messages in the console.
     
  22. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Hey J.A. How are you doing? As you can see from my posts in this thread that I am a bit unsatisfied with this asset so far too. Seems like support dropped off as soon as I started trying it. Luckily I bought it when it was on sale.
     
  23. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hey TokyoDan. Sorry for not getting back to you here. We have had fewer and fewer questions on the forums, and I did not check it recently (most users ask on our knowledge base or support email). My mistake! I answered all your questions on our knowledge base:

    https://gamelogic.quandora.com/grid...d-and-how-should-I-use-Cube-and-MeshTileCells

    (And rest assured, support has certainly not dried up!)
     
    c-Row likes this.
  24. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Hello Herman. I'm glad to see you are still active. Thanks. From now on I will ask questions on the GameLogic Grids knowledge base.
     
    Herman-Tulleken likes this.
  25. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi Jay,

    The tutorial video is slightly out of date, we will add some notes for it.

    For 2D grids, we usually setup the world so that one pixel corresponds to one unity unit. For this setup to work, your camera (assuming it's orthographic), should be set to half the design resolution height (so something like 384 for iPad, for example). This information is missing from the tutorial.

    Then secondly, the old behaviour of cells used to be that their OnClick methods would toggle the highlight state of the cell. To get different behaviour, you would have to override it on your own cells. Since almost no games would use this, we made the default do nothing, and to get any behaviour, you have to override the method in your own cell, or implement the behaviour in the grid.

    The last one is the easiest in your case:

    Code (csharp):
    1. override public void OnClick(PointyHexPoint point)
    2. {
    3.    var cell = Grid[point];
    4.    cell.HighlightOn = !cell.HighlightOn; //toggle
    5. }
    This information changed since we made the tutorial.

    Sorry about this; we will fix it!
     
  26. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    This is a very cool way to deal with the problem, and we have used this technique a lot.

    One thing that you may not realize is that we have functionality for dealing with classification of the cells in this scheme.

    Code (csharp):
    1.  
    2. int pointType = point.GetColoring(2, 0, 2);
    pointType of 0 gives for example corner,
    pointType of 1 gives horizontal wall
    pointType of 2 gives vertical wall
    pointType of 3 gives room

    The three numbers a, b, c of the coloring specify two vectors, the first being u = (a, 0) and the second v = (b, c). These vectors specify the pattern of repetition. (Basically, any vector with the form r*u+s*v with r and s integers, will be the same "color"). More information here: http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/

    It is very useful to understand this as a general technique, as it is a way to adapt division and remainder type algorithms (as you have used) to hex grids too. (There is some detailed explanation of this here: www.gamelogic.co.za/downloads/HexMath2.pdf if you are interested).
     
    c-Row likes this.
  27. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Just some additional background for anyone interested. It took a very long time for us to settle on this style.

    The construction of a grid and a map (these are the two places we use it) is in general very complicated.

    The first idea was to use a bunch of parameters. This quickly becomes a big burden, and required a lot of overloads, and many enum types (to specify alignment, for example). It was also extremely limited. For example, to build a grid in a cross shape, something that is now very simple:

    Code (csharp):
    1. var grid = new RectGrid<TCell>
    2.    .BeginShape()
    3.       .Rectangle(9, 3)
    4.       .Translate(-4, 4) //i think
    5.       .Union()
    6.       .Rectangle(3, 9)
    7.    .EndShape()
    would be impossible except with a lot of extra types that the user would need to know about.

    The second idea was to use modifier methods on the map, something that would look like this:

    Code (csharp):
    1. var shape1 = new RectGridShape.Rectangle(9, 3);
    2. var shape2 = new RectGridShape.Rectangle(3, 9);
    3.  
    4. shape1.Translate(-4, 4);
    5.  
    6. var finalShape = RectGridShape.Union(shape1, shape2);
    7. var grid = new RectGrid<TCell>(finalShape);
    I don't think this is a bad approach, although again there would be a lot of types that the user would need to know. Users would not be able to extend this so easily for their own shapes. (To give you an idea of what is possible; we helped one user implement extension method to support iteration and conditionals, so that he basically had a mini shape building language).

    Now while we spent a lot of time to explore alternatives when we made the decision, it is a long time ago. Since then, a few developments and observations have changed my thinking of what we will probably do in the future:

    Functional friendly style coding is not editor / data-driven friendly. (This also applies a lot to other LINQ idioms we use everywhere). When we introduced the editor grids, this style offered little advantage, and we had to create a lot of new types to store data simply for getting it from the interface into the logic. This makes certain part of Grids hard to maintain. Also, the type of chaining for building more complicated things does not translate to the editor.

    There are better ways to describe shapes. We discovered the first part of this fact when we did the GameMaker implementation, whose crude language does not support any of these methods - we had to completely parameterize shapes as lists of lists of vectors. Recently I also discovered better equations for primitive shapes, which are much easier to manipulate to build compound shapes. This is one of those under-the-hood type things that will both improve performance (ever so slightly) and the interface, especially allowing us to make the editor grids more powerful.

    There are better ways to describe transformations. Another fact that was discovered with both GameMaker Grids and while exploring the fundamentals of grid math. Using matrices for all transformations under the hood leads for a much cleaner design, and will allow much better chaining. (We are still exploring this; it does have some limitations).

    The correct editor idiom for chaining is probably node-based. This is something we learned from our Colors package, and more recently our abstract strategy tool. Node based systems is particularly useful for procedural techniques. We get more and more questions about procedural techniques, and we are spending a lot of time looking at possibilities in this space.

    Not many people need special static shapes. This is a bit of a shame, since we think there are some interesting and unexplored possibilities for games on different shapes, but the truth is most users want rectangles or hexagons, or "pixel edited" shapes (where grid cells are marked arbitrarily as in the shape or not), or procedurally generated shapes (still not very common, but becoming more common).

    ----

    So likely, a hypothetical Grids 2.0 will focus on data-driven techniques that translate well to the editor, and make it easier to implement procedural techniques, and so will probably not use this type of construction.
     
    Last edited: Aug 4, 2015
    movra likes this.
  28. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    827
    Ah, and there I was hoping I had found a unique approach. :D

    I am not sure I completely understand how this works but I will look into it - thank you!
     
    Herman-Tulleken likes this.
  29. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    I'm finally testing the empire side of Aztez against AOT platforms. I'm getting this error on iOS with a Mono backend (not a launch target platform, just a an easy proxy for other AOT platforms like consoles):

    Code (csharp):
    1.  
    2. running hint
    3. UnityEngine.Debug:Internal_Log(Int32, String, Object)
    4. UnityEngine.Debug:Log(Object)
    5. Grid:__CompilerHint__FlatHex_TileCell()
    6. HintsForAOT:Awake()
    7.  
    8. (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
    9.  
    10. ExecutionEngineException: Attempting to JIT compile method 'Gamelogic.Grids.AbstractUniformGrid`2<Gamelogic.Grids.TileCell, Gamelogic.Grids.FlatHexPoint>:.ctor (int,int,System.Func`2<Gamelogic.Grids.FlatHexPoint, bool>,System.Func`2<Gamelogic.Grids.FlatHexPoint, Gamelogic.Grids.FlatHexPoint>,System.Func`2<Gamelogic.Grids.FlatHexPoint, Gamelogic.Grids.FlatHexPoint>,System.Collections.Generic.IEnumerable`1<Gamelogic.Grids.FlatHexPoint>)' while running with --aot-only.
    11.  
    12.   at Gamelogic.Grids.FlatHexGrid`1[Gamelogic.Grids.TileCell]..ctor (Int32 width, Int32 height, System.Func`2 isInside, System.Func`2 gridPointTransform, System.Func`2 inverseGridPointTransform, IEnumerable`1 neighborDirections) [0x00000] in <filename unknown>:0
    13.   at Gamelogic.Grids.FlatHexGrid`1[Gamelogic.Grids.TileCell]..ctor (Int32 width, Int32 height, System.Func`2 isInside, FlatHexPoint offset) [0x00000] in <filename unknown>:0
    14.   at Gamelogic.Grids.FlatHexShapeInfo`1[Gamelogic.Grids.TileCell].MakeShape (Int32 x, Int32 y, System.Func`2 isInside, FlatHexPoint offset) [0x00000] in <filename unknown>:0
    15.   at Gamelogic.Grids.AbstractShapeInfo`5[Gamelogic.Grids.FlatHexShapeInfo`1[Gamelogic.Grids.TileCell],Gamelogic.Grids.FlatHexGrid`1[Gamelogic.Grids.TileCell],Gamelogic.Grids.FlatHexPoint,Gamelogic.Grids.FlatHexPoint,Gamelogic.Grids.FlatHexOp`1[Gamelogic.Grids.TileCell]].EndShape () [0x00000] in <filename unknown>:0
    16.   at Gamelogic.Grids.FlatHexGrid`1[Gamelogic.Grids.TileCell].Rectangle (Int32 width, Int32 height) [0x00000] in <filename unknown>:0
    17.   at Gamelogic.Grids.FlatHexTileGridBuilder.InitGrid () [0x00000] in <filename unknown>:0
    18.   at Gamelogic.Grids.TileGridBuilder`1[Gamelogic.Grids.FlatHexPoint].Awake () [0x00000] in <filename unknown>:0
    19.  
    Hint looks like this:

    Code (csharp):
    1.  
    2. public static bool __CompilerHint__FlatHex_TileCell()
    3. {
    4.     Debug.Log("running hint");
    5.  
    6.     //Ensures abstract super classes for base grids gets created
    7.     var grid = new FlatHexGrid<TileCell[]>(1, 1);
    8.  
    9.     foreach (var point in grid)
    10.     {
    11.         grid[point] = new TileCell[1];
    12.     }
    13.  
    14.     //Ensures shape infpo classes get created
    15.     var shapeStorageInfo = new ShapeStorageInfo<FlatHexPoint>(new IntRect(), p => true);
    16.     var shapeInfo = new FlatHexShapeInfo<TileCell>(shapeStorageInfo);
    17.  
    18.     return grid[grid.First()][0] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null;
    19. }
    20.  
    21.  

    Anything jump out as obvious here? My own coding style is pretty direct, so we haven't had to do any AOT hinting elsewhere in the project. I'm pretty unfamiliar with AOT issues, unfortunately :/
     
  30. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi Matthew,

    The AOT errors are a pain because they are so obscure.

    Luckily there is a quick-fix for your situation. Change your hint to:

    Code (csharp):
    1.  
    2.         public static bool __CompilerHint__FlatHex_TileCell()
    3.         {
    4.             Debug.Log("running hint");
    5.  
    6.             //Ensures abstract super classes for base grids gets created
    7.             var grid = new FlatHexGrid<TileCell>(1, 1);
    8.  
    9.             //Ensures shape infpo classes get created
    10.             var shapeStorageInfo = new ShapeStorageInfo<FlatHexPoint>(new IntRect(), p => true);
    11.             var shapeInfo = new FlatHexShapeInfo<TileCell>(shapeStorageInfo);
    12.  
    13.             return grid[grid.First()] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null;
    14.         }
    15.  
    (Essentially it changes the hint from a grid of arrays of cells to a grid of simply cells. Tri and rhomb grids require the hint for arrays of cells, which we only realized recently.)

    That should do the trick; please let me know if it doesn't.

    Fixing this may expose one or two other AOT issues. If this happens, don't be alarmed. It is almost always a quick-fix, and we have a lot of experience interpreting cryptic error messages and resolving the issues quickly. Just drop the errors here, or we can do a quick interactive Skype (herman.tulleken).

    (And can't wait for Aztez to come out!)
     
  31. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Thanks for the response! Looks like the next AOT block is a GetPointsInRangeCost issue:

    Code (csharp):
    1.  
    2. ExecutionEngineException: Attempting to JIT compile method 'Gamelogic.Grids.FlatHexGrid`1<GridCell>:CloneStructure<bool> ()' while running with --aot-only.
    3.  
    4.   at Gamelogic.Grids.GridExtensions.CloneStructure[Boolean,FlatHexPoint] (IGrid`1 grid, Boolean value) [0x00000] in <filename unknown>:0
    5.   at Gamelogic.Grids.Algorithms.GetPointsInRangeCost[GridCell,FlatHexPoint] (IGrid`2 grid, FlatHexPoint start, System.Func`2 isAcessible, System.Func`3 getCellMoveCost, Single moveRange) [0x00000] in <filename unknown>:0
    6.   at Grid.CalculateReveal (Vector3 start, Single distance) [0x00000] in <filename unknown>:0
    7.   at EmpireGame.UpdateCityVisibility () [0x00000] in <filename unknown>:0
    8.   at EmpireGame.Update () [0x00000] in <filename unknown>:0
    9.  
    10.  
    (I duplicated the compiler hint for our GridCell class too, which was a brief snag).
     
  32. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    OK this is a new one; you need to hint to the compiler to generate the clone method.

    This should do it (you will need to do this for your GridCell, which the compiler complains about, and potentially other cell types too if you use the method on other grids):
    Code (csharp):
    1.  
    2.         public static bool __CompilerHint__FlatHex_TileCell()
    3.         {
    4.             Debug.Log("running hint");
    5.  
    6.             //Ensures abstract super classes for base grids gets created
    7.             var grid = new FlatHexGrid<TileCell>(1, 1);
    8.             var clone = grid.CloneStructure<bool>();            //Added line
    9.  
    10.             //Ensures shape infpo classes get created
    11.             var shapeStorageInfo = new ShapeStorageInfo<FlatHexPoint>(new IntRect(), p => true);
    12.             var shapeInfo = new FlatHexShapeInfo<TileCell>(shapeStorageInfo);
    13.  
    14.             return grid[grid.First()] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null ||
    15.                 clone.First() == new FlatHexPoint(0, 0);  //Added test
    16.         }
    17.  
    Looking at the code the next problem may be the Fill method. Hinting that into existance may be a bit too much, so let me check that first. I don't have a Mac here, but will do it as soon as I get to the office Monday morning.
     
  33. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Looks like that hint is actually throwing a JIT exception:

    Code (csharp):
    1.  
    2. ExecutionEngineException: Attempting to JIT compile method 'Gamelogic.Grids.FlatHexGrid`1<Gamelogic.Grids.TileCell>:CloneStructure<bool> ()' while running with --aot-only.
    3.  
    4.   at Grid.__CompilerHint__FlatHex_TileCell () [0x00000] in <filename unknown>:0
    5.   at HintsForAOT.Awake () [0x00000] in <filename unknown>:0
    6.  
     
  34. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    OK I will check it out. Unfortunately I have not compiled to iOS for a while so I am doing the upgrade dance (XCode and OS X), but as soon as everything is up I will get to it.
     
  35. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Sorry for taking so long to reply (my developer licence lapsed, so had to get that sorted out first).

    I cannot replicate your error.

    Here is the exact test code I used:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Linq;
    5.  
    6. using Gamelogic.Grids;
    7.  
    8. publicclass Main : MonoBehaviour
    9. {
    10.     public MyCell cellPrefab;
    11.  
    12.     public static bool __CompilerHint__FlatHex_TileCell()
    13.     {
    14.         Debug.Log("running hint");  
    15.  
    16.         //Ensures abstract super classes for base grids gets created
    17.         var grid = new FlatHexGrid<TileCell>(1, 1);
    18.         var clone = grid.CloneStructure<bool>();            //Added line
    19.  
    20.         //Ensures shape infpo classes get created
    21.         var shapeStorageInfo = new ShapeStorageInfo<FlatHexPoint>(new IntRect(), p => true);
    22.         var shapeInfo = new FlatHexShapeInfo<TileCell>(shapeStorageInfo);
    23.  
    24.         return grid[grid.First()] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null ||
    25.             clone.First() == new FlatHexPoint(0, 0);  //Added test
    26.     }
    27.  
    28.     public static bool __CompilerHint__FlatHex_MyCell()
    29.     {
    30.         Debug.Log("running hint");
    31.  
    32.         //Ensures abstract super classes for base grids gets created
    33.         var grid = new FlatHexGrid<MyCell>(1, 1);
    34.         var clone = grid.CloneStructure<bool>();            //Added line
    35.  
    36.         //Ensures shape infpo classes get created
    37.         var shapeStorageInfo = new ShapeStorageInfo<FlatHexPoint>(new IntRect(), p => true);
    38.         var shapeInfo = new FlatHexShapeInfo<MyCell>(shapeStorageInfo);
    39.        
    40.         return grid[grid.First()] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null ||
    41.             clone.First() == new FlatHexPoint(0, 0);  //Added test
    42.     }
    43.  
    44.     public void Start()
    45.     {
    46.         if (!__CompilerHint__FlatHex_TileCell ())
    47.             return;
    48.  
    49.         if (!__CompilerHint__FlatHex_MyCell ())
    50.             return;
    51.  
    52.         Debug.Log ("Hints ran");
    53.  
    54.         var grid = FlatHexGrid<MyCell>.Hexagon(4);
    55.  
    56.         foreach (var point in grid)
    57.         {
    58.             var cell = Instantiate(cellPrefab);
    59.  
    60.             //leave out other stuff for now
    61.         }
    62.  
    63.         var costs = Gamelogic.Grids.Algorithms.GetPointsInRangeCost(
    64.             grid,
    65.             FlatHexPoint.Zero,
    66.             p => true,
    67.             (p,q) => 1,
    68.             3);
    69.  
    70.         Debug.Log (costs.First());
    71.     }
    72. }
    73.  
    74.  
    75.  
    MyCell is an empty subclass of SpriteCell.

    Both hints run fine, and I don't get any JIT errors. With the old Mono compiler, the code works as in the editor, but with IL2CPP I get an null pointer exception, which is equally troubling but different from your error.

    Can you please give me some more info on your settings (Unity version, and a screenshot of your player settings, XCode version)?
     
    Last edited: Aug 19, 2015
  36. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Thanks again for checking in on this! I know all too well the pain of Apple's developer stuff (I re-sign IPA uploads for Unity Awards and other curation systems, ugh).

    Anyway:

    I move all of our big Asset Store libraries into Standard Assets so they're in the earliest compilation pass. It actually makes a pretty big (2x) difference in compile times for us. So on a hunch, I moved the Gamelogic directory out of Standard Assets and into the project root, so it'd be in the last compile pass along with our game logic.

    And it worked!

    In our setup, "GridCell" inherits from TileCell but includes hooks into our game logic and everything else. I guess the compiler gets confused between compilation passes? It's hard for me to push GridCell into the earlier compilation pass, since its dependencies eventually touch a lot of the game code.

    For Aztez I can just leave Grids out of Standard Assets (if you're curious, it seems to increase compile times for me from 8s to 11s).

    If you're interested in a repro over there, you should be able to move the Gamelogic folder into Standard Assets while keeping MyCell in the project normally. Note that Unity still has a lot of annoying bugs with moving things in and out of Standard Assets/Plugins/etc folders, so you'll probably want/need to close and reopen Unity after you move the folder...
     
  37. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Oh, and I see an IL2CPP null reference too. Shows up as:

    Code (csharp):
    1.  
    2. NullReferenceException: A null value was found where an object instance was required.
    3.   at EmpireGame.DoTurn () [0x00000] in <filename unknown>:0
    4.   at EmpireGame.Start () [0x00000] in <filename unknown>:0
    5.   at Gamelogic.Grids.PolygonGridMap`2[Gamelogic.Grids.CairoPoint,Gamelogic.Grids.PointyHexPoint].<PolygonGridMap>m__9E (IEnumerable`1 e) [0x00000] in <filename unknown>:0
    6.  
    7. (Filename: currently not available on il2cpp Line: -1)
    8.  
    Can you file a bug report on your end? Your repro is definitely going to be cleaner than mine (Aztez is pretty tightly interwoven at this point). It could very likely be an IL2CPP, and Unity is always keen to fix those.
     
  38. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
  39. Braza

    Braza

    Joined:
    Oct 11, 2013
    Posts:
    126
    Hi! I have a Pro version and recently tried to modify this hills example to be Terrain + RectMap combo.
    It worked with Hexes, but Rect... http://screenpresso.com/=mPFmd

    So I went back to investigating how it works in the simples case, without terrain, but failed to achieve even the 10*10 rect grid. It is always single. Is RectMeshGridBuilder supposed to be working? It doesn't seem to. HexMeshGridBuilder does work though.

    And one more issue popped out.
    Trying to generate that grid results in Unity constantly consuming 25% of CPU and not being able to shutdown Editor properly due to the processes on the screenshot I believe http://screenpresso.com/=2f8kg
     
    Last edited: Sep 6, 2015
  40. WJ

    WJ

    Joined:
    Oct 25, 2012
    Posts:
    97
  41. Jonathan-Bailey

    Jonathan-Bailey

    Joined:
    Aug 12, 2013
    Posts:
    79
    Hi there,

    Grids Lite was made free for a period back in May/June but it's back to being a paid asset. I've updated the forum and blog posts to explain that the offer is no longer avaiable. If there are any offers or sales in the future we'll be sure to let you know!
     
  42. WJ

    WJ

    Joined:
    Oct 25, 2012
    Posts:
    97
    Ahh ok, I have a full version but I was hoping there would be a free rect version that I could distribute with an open source project. I pretty much just need rect + pathfinding (smooth) for it. Would have saved me having to roll my own :(
     
  43. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    I answered your first question here:

    https://gamelogic.quandora.com/grid...911eca/Why-is-RectMeshGridBuilder-not-working

    There is a bug, and for now there is a fix too. We will fix it properly in the next update.

    The bug may also be the performance culprit; I could not duplicate the issue. Can you place check if it still happens after the fix?
     
  44. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Just to be clear, even if it was still free, you would most definitely not be able to redistribute Grids in an open source project.

    From the asset store terms (https://unity3d.com/legal/as_terms):
    You can use Grids in any project, commercial and otherwise royalty free. But you cannot redistribute the code or derivative works.

    ----

    That said, I understand exactly where you are coming from. Figuring out a good (fair and useful) way to mix code is a tricky problem. There are many assets in the asset store that could enhance Grids if we could include it, but we have not figured out a good way to do this - both logistically, and business-wise. In fact, we would like better ways to distribute Grids with our own other packages. Similarly, Grids could enhance many other packages too (like it would in your project), but again, it's tricky to figure out a good way to do it.
     
  45. Braza

    Braza

    Joined:
    Oct 11, 2013
    Posts:
    126
    I am able to build a RectMeshGrid now, thanks! http://screenpresso.com/=qP21d

    Upd-----------------

    Although building 100*100 tiles mesh maps really takes some time on Core i7. And it triggers some Clustering job in the Editor.
    Can this be due to the fact that numbe of vertices are x4 times of number than they should be? If I understand the construction process correctly.

    Yeah, seems like I quickly run out of bounds with vertices with 150*150 rect grid
    http://screenpresso.com/=MzUwf

    Given that, it mught have not been a great idea to go that way. Now I'd like to try put sprite 3d grid over terrain and I have impediments.
    I tried to follow instructions on your site.

    http://gamelogic.co.za/grids/documentation-contents/quick-start-tutorial/working-with-maps/ and http://gamelogic.co.za/grids/featur...-a-rectangular-grid-on-the-inside-of-a-torus/ - these suggests to implement IMap3D - that's fine.
    But this http://gamelogic.co.za/grids/documentation-contents/quick-start-tutorial/making-your-own-maps/ states that I need a CustomMapBuilder that returns WindowedMap, not IMap3D
     
    Last edited: Sep 8, 2015
  46. Timboc

    Timboc

    Joined:
    Jun 22, 2015
    Posts:
    234
    Hi guys, just trying out the 30 day demo and so far I'm really impressed. Very comprehensive and well written. Kudos. For performance reasons I would have loved to have tried out the hex-grid with path-finding on iOS before purchasing but I understand why and I'll likely end up purchasing regardless.

    In the meantime I just have a quick query. At the moment using the 30 day trial, "TrialGUI.OnGUI" is using up like 65% of my cpu on desktop. Sometimes it's less but it's always pretty high - any clue as to how I can mitigate this? Perhaps something I need to avoid?

    Update: Performance is correlated to grid size. I'm currently using a 24x22 Rectangle grid of a custom Sprite PointyHexCell.

    Many thanks in advance.
     
    Last edited: Sep 9, 2015
  47. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    Pretty much my situation too. I already own pro and I think its a great asset. When I saw lite was free I got excited and decided to make an asset I'm writing require grids lite. I didn't realize it was free for a limited time. I'll have to roll my own solution to include with my asset, which sucks because I really did like working with grids.
     
  48. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Indeed, there are some limitation on the number of verts, but only per mesh. The right way to solve it is to break the mesh total mesh you want to render into smaller ones. My guess would be that this will give you better performance than thousands of sprites, but it is worth testing using an ordinary grid builder first. Note that while Unity can handle thousands of objects pretty well (as builds), the editor cannot, so you may be experiencing speed degradation that will not be in a build (at least not for Desktop). Finally, make sure you have the gizmos switched off if you work on large grids with sprites as cells (from the Gizmos toolbar, deselect SpriteCell), otherwise it will also be extremely slow. If after this test you are happy with the speed, and you decide to go with sprites afterall, then I can help you create the map.
     
    Braza likes this.
  49. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi Timboc,

    The low speed is caused by the coordinate gizmo rendering, which you can switch of (From the Gizmo's button on the scene toolbar, deselect SpriteCell). The speed increase is dramatic, and you will see that you can handle grids that are quite large without problem.
     
    Timboc likes this.
  50. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    As I said above, even when Free you would not be able to distribute Grids as a part of another asset (this is true for all assets in the Asset Store). However, if there is some way we can collaborate, we are open for discussion; perhaps you can send us an email or we can have a chat over Skype about what exactly you want to do?