Powerful Generics Added! Grid System in Unity (Terraria, Minesweeper, Tilemap)

Поделиться
HTML-код
  • Опубликовано: 29 дек 2024

Комментарии • 279

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  5 лет назад +14

    Play 7 Awesome Games and help support the channel! (Action, Strategy, Management)
    Get the Game Bundle at unitycodemonkey.com/gameBundle.php
    See what I'm teaching here applied to real games!

    • @lyricsmaker-poplyricsmaker1183
      @lyricsmaker-poplyricsmaker1183 3 года назад

      how can I get your code from your package so I can change it a little bit?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      @@lyricsmaker-poplyricsmaker1183 There's a link in the description

    • @rambovalle8881
      @rambovalle8881 3 года назад +1

      Help.
      public Vector3 GetWorldPositionFromValue(T value)
      {
      Vector3 pos = new Vector3(0, 0, 0);
      for (int x = 0; x < width; x++)
      {
      for (int y = 0; y < height; y++)
      {
      if (gridArray[x, y] == value)
      {
      pos = GetWorldPosition(x, y);
      }
      }
      }
      pos.x += 5.5f;
      pos.y += 5.5f;
      return pos;
      }
      error CS0019: Operator '==' cannot be applied to operands of type 'T' and 'T'

    • @mrmogelost6720
      @mrmogelost6720 3 года назад

      ​@@rambovalle8881 Change your if statement that checks the value parameter to this:
      if (gridArray[x, y].GetType() == typeof(value))
      I think it just might work, I'm a bit of an intermediate myself.

    • @rambovalle8881
      @rambovalle8881 3 года назад

      @@mrmogelost6720 Nope (ToString() works but that doesnt work with evrything because if its custom class it will just comparre names if i remember correctly but i will use it unitil something better comes out)

  • @pawepawowski9506
    @pawepawowski9506 4 года назад +129

    Please reorder your Grid System in Unity playlist this should be 3rd, not 2nd part because you use and modify code from the heatmap video and it is super confusing. I almost rewatched full grid video to search what I missed but then I noticed that the heatmap video upload date is between this and first one so after heatmap video it makes so much more sense.

  • @seanloughran6714
    @seanloughran6714 2 года назад +7

    Being able to pass functions as a parameter is so handy. As always, super amazing video filled with so much knowledge!

  • @Xerisis
    @Xerisis 3 года назад +9

    So the issue with the HeatMapVisual file getting errors is that the Grid class has the same name as a built-in Unity class. So as soon as it was changed to generics, the HeatMapVisual script started referencing the Unity class instead of the Grid class we created. Comment that script out until you hit the part in the vid where it gets fixed.

  • @cahydra
    @cahydra 2 года назад +1

    Being able to use any type is fantastic

  • @gordorodo
    @gordorodo 5 лет назад +18

    Great tutorial! Thanks man!
    I would change just one thing on your implementation.
    Your HeatMapGridObject shouldn't hold a reference to the grid since you are creating an unneeded cross-reference plus the need of adding all those parameters to the constructor.
    What I would do is have the HeatMapGridObject raise an event whenever it is modified, and whoever knows that GridObject can subscribe to that event, in our case, your Grid.
    So, the Grid, when creating all its objects, it also registers to the event and handles it in whatever way it desires.
    It's a very simple change but I believe it enforces better encapsulation and simplifies the construction.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +8

      Yup that is indeed another approach and actually what I use in the Grid System that I've used in my games for several years now.
      I tried to keep the video simple so I figured having the object contact the grid would be easier to follow than events.

    • @gordorodo
      @gordorodo 5 лет назад +3

      @@CodeMonkeyUnity yeah good point, adding that doesn't necessarily add to the grid system tutorial and might make things confusing for beginners.
      Anyways, great job bro, love your vids!

    • @BetrayedGecko
      @BetrayedGecko 4 года назад

      @@gordorodo Can you go into a bit more detail about how you'd do this with generics?
      So do you create a delegate in your HeatMapObject? If so how do you get the grid to subscribe to that event without creating a dependency on the HeatMapObject?

    • @erfrid
      @erfrid 4 года назад

      This is not possible if you want the grid to be generic. It would need to know about specific types to subscribe to their OnChanged event. Other than creating a big type casting mess, which creates lots of dependencies, there is no other way than what is shown in the video, but I'd be happy to be proven wrong!

    • @tomfebry
      @tomfebry 3 года назад +4

      @@erfrid ​​You can just use an interface like IGridObject and have the event in there, couldn't you?
      public class Grid where TGridObject: IGridObject
      public interface IGridObject {
      public event Action OnValueChanged;
      }
      gridObject.OnValueChanged += () =>
      {
      OnGridValueChanged?.Invoke(this, new OnGridValueChangedEventArgs {x = x1, y = y1});
      };
      _gridArray[x, y] = (TGridObject) gridObject;

  • @universegames7692
    @universegames7692 5 месяцев назад +1

    OMG i made by this amazing tutorial about half a day, and now spend another half to understand all

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 месяцев назад +1

      Great job on taking your time to truly learn! Keep at it!

  • @Definitely_a_Fox
    @Definitely_a_Fox 5 лет назад +6

    Ah! Having a Tilemap system would be very nice! Unity's Tilemap system doesn't exactly do what I want it to do, but making my own may help me out!
    Just going to wait for the next video!

  • @nbixel
    @nbixel Год назад +1

    Excellent presentation of Lambda use, when you havent done it in a while its a great refresher

  • @zodi4991
    @zodi4991 Год назад +2

    @CodeMonkeyUnity Hello, around 16:20, when I click on my grid it doesnt change the value. But I have written everything you did and I have no errors, what could be causing it to not work?

  • @Robocat754
    @Robocat754 2 года назад +3

    One small error I think. You should assign mathf.clamp to value so that when adding value it will never exceed 100. But it's not that relevant to the topic of this video. Excellent tutorial! Really appreciate it!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      Yeah for a Heatmap adding a little validation to the values would be a good idea.
      I'm glad you found the video helpful!

  • @Wispii
    @Wispii 3 года назад +2

    Been following the video till 17:02, and my code is now telling me that in the test script that SetGrid(grid) "Cannot convert from "Grid" to "Grid"", as well as saying that the type or namespace of "HeatMapGridObject" could not be found in the generics script. I checked through your code and all of my code lines up, yet i'm getting the error.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Sounds like you're using 2 different types, one just HeatMapGridObject and another one named the same but inside another class named Test

  • @HorizoneMeNol
    @HorizoneMeNol 3 года назад +8

    7.47 I follow all step
    i need to cancle out heatmapvisual
    to make it use-able
    and my heatmap bool visual can change into true but not turning green

  • @Eck314
    @Eck314 4 года назад +5

    @Code Monkey - It seems like the Heat Map video should be in a different order. Can you drag the Heat Map video up to be the 2nd video in the Play List?

  • @aegisdota_
    @aegisdota_ Год назад +3

    Hey! There was an issue that Func statement at 10:25 wasn't recognizable by compiler, I solved it just adding System.Func instead of simple Func. I don't understand why it should be like this... If someone says, it would be nice

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +2

      Func exists inside the System namespace so it's just because you don't have "using System;" on top

    • @aegisdota_
      @aegisdota_ Год назад

      @@CodeMonkeyUnity So stupid issue... I should have notice that, anyway TY, and for great tutorials too!

  • @jwalkaz6097
    @jwalkaz6097 3 года назад +3

    I know this is old but at 6:00 when you skip from code to playing, The heatmap visual script gives me errors so I cant actually test what we did. the error says The type name 'OnGridValueChangedEventArgs' does not exist in the type 'Grid'

    • @aldenmauro2227
      @aldenmauro2227 3 года назад +3

      I was able to fix this by adding the type of the grid after each Grid in the code. There were two spots not covered in the video where you have to add the type. E.g.: Grid.OnGridValueChangedEventArgs e, changed to, Grid.OnGridValueChangedEventArgs e.

    • @aquan11111
      @aquan11111 3 года назад

      @@aldenmauro2227 Thanks man

  • @BrunevaStudios
    @BrunevaStudios 4 года назад +11

    This tutorial was very confusing for me. When you change the Grid class to hold a generic type, the HeatMapVisual class shows a bunch of errors, and while you do fix them by creating HeatMapBoolVisual script and going over whats wrong, it is not clear why you can test the original map with all those errors, since you haven't created HeatMapBoolVisual yet. I've been cracking my head trying to fix them and it just won't work.

    • @collinfarrell9718
      @collinfarrell9718 4 года назад +1

      I had the same issue. I just commented out that entire script. I'm guessing during editing maybe some little details like that get left out sometimes.

    • @unnamedsettler9540
      @unnamedsettler9540 4 года назад +1

      @@collinfarrell9718 I know I'm really late to this, but I don't think you were wrong for commenting it out. at 6:22, he has the beginning of a block comment (the /*) right at the start of his script above "private Grid grid;" in Unity's Inspector window, and I can only assume he ended it after everything, since it shows majority of the code and I didn't see the ending comment mark in it.

    • @warrenklassen1130
      @warrenklassen1130 2 года назад +2

      I had the same issue but the real problem was that you originally reference GRID, when he introduces generics the format changes to GRID so GRID will no longer find it. If you change all references of GRID to GRID in the HeatMapVisual class it then works again.

  • @magictimm4090
    @magictimm4090 4 года назад +3

    Followed your video until 17:30. You said "debug mode is off". Is this the reason for having numbers instead of colors in the grid? I cannot find the error in my code. It runs correct. But I have no colors.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Your quads should be receiving their correct color on UpdateHeatMapVisual();
      Add a Debug.Log to make sure that function is running and maybe a log on a specific position (0,0) and click on it to see if it changes

    • @magictimm4090
      @magictimm4090 4 года назад

      @@CodeMonkeyUnity Thank you. I added heatMapGenericVisual.SetGrid(grid); and now I have the correct number 0 (5,10...) and the correct color in the quad. But in your video the number is not shown. I used the code from your website in a
      separate testing project. And it's the same result. Number and color. It's not a big issue but it would be interessting whats the reason for this.

    • @HorizoneMeNol
      @HorizoneMeNol 3 года назад +1

      @@magictimm4090 how did you do it ?

    • @magictimm4090
      @magictimm4090 3 года назад

      @@HorizoneMeNol Sorry, cannot find the code

    • @JaKayne
      @JaKayne 3 года назад +4

      Add "heatMapGenericVisual.SetGrid(grid);" at the end of the Start method in the Testing class and it works fine. It is not shown in the video.

  • @gadgetboyplaysmc
    @gadgetboyplaysmc 4 года назад +38

    You never really showed how you created the EventHandler OnGridValueChanged. I mean you showed a little bit of it in the first video on Grid Systems. But man... The way your tutorials are so interconnected and sequentially inconsistent made this really complicated to follow. Another thing is how you use the your Utils class, which may be very useful, but it was pretty difficult to actually absorb the information when there's that little black box aspect in the tutorial. I mean I can't really complain since all of this is free, so believe me I'm truly grateful. It's just super frustrating to end up being stuck in the middle because I didn't know how that one method or variable is supposed to exist. In the end I kinda got it down together tho.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +11

      Events are pretty basic C#, I covered them here ruclips.net/video/OuZrhykVytg/видео.html
      ruclips.net/video/7VlykMssZzk/видео.html
      This is a pretty complex class, if you're a beginner then it will take you more than just a few minutes to understand everything.
      It's your learning journey, take your time, it's not a race.

    • @lens3973
      @lens3973 3 года назад +1

      @@CodeMonkeyUnity events are basic c#, so you don't show them? That's awful logic. Just admit the mistake, and put the fix in the description. How you are acting is immature and egotistical. How is everything else in this video not also basic c#? Isn't that the point of the tutorials, to help beginners learning c#? Or is it to provide incomplete tutorials so people have to sign up to your stupid website just to download the files. Oh, and also buy my coding course (is that where you actually teach basic c#?). You obviously only have your own interests at heart.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +7

      @@lens3973 What?

    • @lens3973
      @lens3973 3 года назад +1

      @@CodeMonkeyUnity what part didn't you understand? You purposefully limit your free content just to sell your courses. Why aren't your project files on GitHub like every other tutorial on YT? You don't care about the coding or sharing knowledge, just getting your $$$.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +9

      ​@@lens3973 I don't even have any course related to this Grid System or C# itself. All of the videos in the Grid System series are completely free right here on RUclips ruclips.net/p/PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722
      All of the C# videos that I've made are also all here completely free on RUclips ruclips.net/p/PLzDRvYVwl53t2GGC4rV_AmH7vSvSqjVmz
      And the project files are completely free to download, none of the project files from my 450+ videos are behind a pay wall.
      So again I have no idea what on earth are you talking about, 90% of everything I make is completely free, are you confusing me with someone else?

  • @Erfo7783
    @Erfo7783 3 года назад +11

    Hello, thanks for yet another great video, awesome pace, awesome concepts. I have a question, at minute 16 you implement a bunch of code to trigger the grid update, creating also a cross dependency between the grid and the object. Isn't it easier if you just call the set function from the testing script?
    // I use a dictionary for the grid cells)
    if (Input.GetMouseButtonDown(0) && index >= 0)
    {
    HeatMapObject heatMapObject = myGrid.GetGridObject(index);
    if (heatMapObject != null)
    {
    heatMapObject.AddValue(cellValueStep);
    myGrid.SetGridObject(index, heatMapObject);
    }
    }

  • @KetoneCharger
    @KetoneCharger 2 года назад

    thanks for this. i've bought your course too!

  • @ognjenmarceta
    @ognjenmarceta Год назад

    Your grid system is super cool, here is one idea of potential future tutorial if you ever get interested in it. Combination of Wave function collapse and grid system to generate levels.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +2

      Yup that's one topic I've had on my to-do list for a long time, it's a really interesting way of generating levels, I've never used it myself so need to find the time to really research it.

  • @LautaroArino
    @LautaroArino 2 года назад +1

    Hey CM! Great stuff as usual. Do you have any tips on how to persist such a grid? Like is it possible to have a scriptable object that can save a grid object with a generic type?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +2

      For saving on a scriptable object you'd need a way to serialize your generic type. So basically what I covered in the Tilemap video with a Save Object for the generic type
      unitycodemonkey.com/video.php?v=gD5EQyt7VPk
      unitycodemonkey.com/video.php?v=6uMFEM-napE

    • @LautaroArino
      @LautaroArino 2 года назад

      @@CodeMonkeyUnity Amazing. You are just a chest of treasures.

  • @yinttalmaixyond7661
    @yinttalmaixyond7661 5 лет назад +2

    Excellent contents! Thank you!

  • @theGreaterAwareness
    @theGreaterAwareness 8 месяцев назад

    You have magic code in the video that is never revealed as to its addition to the grid.cs. At 6:04 is the line. "debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize" is all we can see but the creation of that line is never shown in any of the videos in the creation of that script. Therefore, how can the audience know what the end of that line is? As there is no link to say "Find out how to remove the error message by typing in the actual code".

    • @theGreaterAwareness
      @theGreaterAwareness 8 месяцев назад

      For those that got stuck on the same problem, here is the missing code that is required for the script to function: debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter);

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 месяцев назад

      You can download the project files linked in the description or just my utilities class if you want to read the whole source code.
      It just does exactly what the function says, it spawns a World Text object on that position.

  • @Toopa88
    @Toopa88 5 лет назад +1

    Just thought about world generation earlier that day, nice 👌

  • @josevalenzuela4540
    @josevalenzuela4540 4 года назад

    Dont know why after define the TGridObject in the Grid script, now Unity does not show the lines (yet the bool values) from 6:12

  • @TruckerJoeOfficial
    @TruckerJoeOfficial 4 месяца назад

    Your grid system is really awesome! Thank you for the tutorial. I want to set it on top of a model from a 3d island with mountains and rivers and so on which I modeled in Blender.
    So some of the grid cells are not walkable. Do you have an idea how I can set them as not walkable during code and not select them all by hand?

  • @rogeriosartori5644
    @rogeriosartori5644 5 лет назад +3

    The type or namespace name 'Func' could not be found (are you missing a using directive or an assembly reference?), How to fix it?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +7

      On the top of your file add:
      using System;

    • @IronOreAgate
      @IronOreAgate 4 года назад +1

      @@CodeMonkeyUnity Thank you!!

  • @fartedididnot3685
    @fartedididnot3685 2 года назад

    Im getting an error on 7:39 about null reference.
    NullReferenceException: Object reference not set to an instance of an object
    Grid`1[TGridObject].SetValue (System.Int32 x, System.Int32 y, TGridObject value) (at Assets/Scripts/Grid.cs:88)
    Grid`1[TGridObject].SetValue (UnityEngine.Vector3 worldPosition, TGridObject value) (at Assets/Scripts/Grid.cs:96)
    Testing.Update () (at Assets/Scripts/Testing.cs:21)
    Can't figure it out. Also how do I get the texture for the material? Thanks

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
      You mean the background texture? I grabbed it from the asset store, don't remember which one, there's thousands of free textures.

  • @silentsammiee
    @silentsammiee 3 года назад +1

    Hello, Im new to coding but I realy love it, 1 question. I tried my best to copy your code and when im testing at 7:35, yours turn green while mine stays black. are there any possible mistakes in my part?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Does it turn from False to True? Use Debug.Log to verify that you're calculating the correct mouse position and grid position

    • @silentsammiee
      @silentsammiee 3 года назад

      @@CodeMonkeyUnity yes, im pretty satisfied with just having the inteded result. sooner or later, I am continuing to your series until the heatmap video. Thanks for replying even the video is long ago.

    • @vincentphillips2933
      @vincentphillips2933 3 года назад

      @@CodeMonkeyUnity Same problem as @Silent Sam Plays. I've followed everything to a T and still no success. The only way I could ever get it to work was to create a 2nd grid script specifically for the color changing based on the heatmap but with debugging turned off. Then in the testing script create the 2nd grid in the same exact position with exactly the same dimensions and specs. Instead of calling SetValue from the Grid class in the grid script. I had to call AddValue from the Grid class created with the heatmap video(The 2nd grid script specifically for color changing). Is this the way you made it work?
      //Variables
      [SerializeField] private HeatMapVisual heatMapVisual;
      [SerializeField] private HeatMapBoolVisual heatMapBoolVisual;
      private Grid grid;
      private Grid gridBool;
      // Start is called before the first frame update
      void Start()
      {
      grid = new Grid(20, 10, 15f, Vector3.zero);
      gridBool = new Grid(20, 10, 15f, Vector3.zero);
      heatMapVisual.SetGrid(grid);
      heatMapBoolVisual.SetGrid(gridBool);
      }
      // Update is called once per frame
      void Update()
      {
      if (Input.GetMouseButtonDown(0))
      {
      Vector3 position = UtilsClass.GetMouseWorldPosition();
      grid.AddValue(position, 100, 100, 1);
      gridBool.SetValue(position, true);
      }
      }
      From the video it doesn't show this yet yours still works as intended by changing not only to True but also to green. However in the video you do disable the original HeatMapVisual GameObject. Whenever I do this mine surely doesn't work. The only way I get the same results as you at this point is by doing what I stated. Was this just a cheeky work around that I did? Is my thinking completely off? Any replies are greatly appreciated.

    • @ThaDewey
      @ThaDewey 2 года назад

      For me, it was the eventHandler. I had commented it out since at the beginning of the video because off all the errors i was getting.
      so do you debuts and check to see if the EventHandler is firing as it should

  • @yaroslavmakarov2218
    @yaroslavmakarov2218 5 лет назад +2

    Amazing content! Thank you very much!

  • @Ryan-ww7un
    @Ryan-ww7un 2 года назад +1

    I'm really interested in learning how to eliminate the coupling between the grid object and the grid. So far I understand I can use a generic type constraint on the grid class to limit the type to those that implement a given interface. I'm unsure about the structure of the interface, and what changes I'd need to make to the grid and object classes. Any help would be greatly appreciated!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +2

      By using generics it's already decoupled, you can define a specific GridObject for whatever you want to build. I've built many systems on top of this and they all use different GridObject definitions
      ruclips.net/video/Cdcn6uK9gPo/видео.html
      ruclips.net/video/fxaDBE71UHA/видео.html

  • @zZMazeZz
    @zZMazeZz 4 месяца назад +1

    If you want to re-create the 'diamond-shaped heat map' using the new HeatMapGridObject from this video, add this method to your HeatMapGridObject. Then pass in the two range values in your testing script like 'heatMapGridObject.AddValue(5, 5, 5);'
    // Diamond Generator
    public void AddValue(int addValue, int fullValueRange, int totalRange) {
    Debug.Log("Adding value with range");
    int lowerValueAmount = Mathf.RoundToInt((float)addValue / (totalRange - fullValueRange));
    for (int x = 0; x < totalRange; x++) {
    for (int y = 0; y < totalRange - x; y++) {
    int radius = x + y;
    int addValueAmount = addValue;
    Debug.Log(addValueAmount);
    if (radius > fullValueRange) {
    addValueAmount -= lowerValueAmount * (radius - fullValueRange);
    }
    grid.GetGridObject(this.x + x, this.y + y)?.AddValue(addValueAmount);
    if (x != 0) {
    grid.GetGridObject(this.x - x, this.y + y)?.AddValue(addValueAmount);
    }
    if (y != 0) {
    grid.GetGridObject(this.x + x, this.y - y)?.AddValue(addValueAmount);
    if (x != 0) {
    grid.GetGridObject(this.x - x, this.y - y)?.AddValue(addValueAmount);
    }
    }
    grid.TriggerGridObjectChanged(x, y);
    }
    }
    }

  • @bryceblazegamingyt9741
    @bryceblazegamingyt9741 3 года назад

    Hello! Im having a problem at 5:52, after I change the Grid, to Grid. It gives me 'Cannot implicitly convert type 'Grid' to 'UnityEngine.Grid' Am I missing something?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Sounds like your code is trying to use the built-in Unity Grid instead of the one created in this video

    • @bryceblazegamingyt9741
      @bryceblazegamingyt9741 3 года назад

      @@CodeMonkeyUnity Wow thanks! I didn't expect a reply. This video is pretty old.

    • @bryceblazegamingyt9741
      @bryceblazegamingyt9741 3 года назад

      I was able to fix the error by replacing "Grid grid = new Grid(PARAMS);" with "Grid grid = new Grid(PARAMS);"

  • @julianhoogendoorn8640
    @julianhoogendoorn8640 3 года назад +1

    Hey guy, I'm loving your tutorials. I'm just a bit confused about the playlist they're in. When I followed the first one about making the grid, this pops up as the next one. But you already did heatmap related stuff in here. And that is the 4th video in the playlist, which in turn seems to build on previously unbuilt stuff. Is it the correct order?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      This Grid class wasn't really planned ahead of time, I just started building and kept building on it, so there were some simple things I made outside of the videos and the videos weren't planned to go from one directly to the next.
      The order in the Playlist is based on learning the core first and then various implementations of it. You don't need to make the heat map or the tilemap to learn how it works, but watching those videos will give you more ideas for various use cases.

  • @ArmaanVB
    @ArmaanVB 5 лет назад +2

    I'm using the grid for a building system. I can select an object and click on the grid and it builds it and sets the tile to occupied. However, I cant figure out how to make it work with objects that would take arbitrary tile sizes such as 2x3, 4x9 etc. how do I mark all those tiles as occupied instead of only the one i clicked on?
    * Assuming the objects already know their own size
    Thanks

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +4

      When you're adding it to the grid do a cycle going through the width and height of your object and fill those up.
      So instead of modifying the grid directly make a function that takes the object type and X Y position, normally I use the Lower Left corner of the object as its origin
      So if my object is 2x2 then I make a function that takes X, Y and occupies X, Y, X + 1, Y + 1

    • @ArmaanVB
      @ArmaanVB 5 лет назад

      @@CodeMonkeyUnity Thanks! that got it working great!
      Now for removing a placed object I'm storing a list of TileObjects it occupies on each object so when I click remove on the object it sets all tiles in that list to unoccupied.
      Is there a better way to do this?

    • @devangmakwana5277
      @devangmakwana5277 4 года назад +1

      @@CodeMonkeyUnity can you please make video on this

  • @lukehughes6943
    @lukehughes6943 2 года назад +1

    When you changed to GetGridObject, how did your Visual Studio change the other references to it? Mine didn't do that, I had to do them manually, but the way yours worked is obviously way better.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +3

      The default shortcut for Rename is Ctrl + R + R
      It renames all instances of the selected function/class/variable

    • @lukehughes6943
      @lukehughes6943 2 года назад

      @@CodeMonkeyUnity May be the most valuable thing I've learnt so far! Love your work

  • @ahmetakifsahin6151
    @ahmetakifsahin6151 2 года назад +1

    Guys, please help me. When i'm trying to do the same, i get the error
    Grid' does not contain a definition for 'GetGridObject' and no accessible extension method 'GetGridObject' accepting a first argument of type 'Grid' could be found (are you missing a using directive or an assembly reference?)
    I dont know what to do.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      Looks like you're passing in the Grid reference as a parameter to GetGridObject instead of the position

  • @jean-michel.houbre
    @jean-michel.houbre 4 года назад

    Super video, very clear and which shows the interest of the generics.
    I'm just pointing out that the normalized value is incorrect, because it ignores the minimum value: (value - min) / (max - min). In the video, min is 0, so no visible error.
    I did not find the town map video indicated at the end of the video (20:12). Unless it is "Custom Tilemap in Unity with Saving and Loading (Level Editor)"?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Yup it's the Tilemap video ruclips.net/video/gD5EQyt7VPk/видео.html

  • @Vulpiro
    @Vulpiro 3 года назад

    5:46 I changed everything but after change to Generics i got error in testing class

    • @stephenperry1006
      @stephenperry1006 3 года назад

      What error message are you receiving? If you've already solved the problem, nevermind!

  • @Challenger.55
    @Challenger.55 Год назад

    Could you please elaborate if I was to add grid component to my terrain how can this make it easier then this approach ?

  • @coldwire3684
    @coldwire3684 5 лет назад +1

    Implementing the IEnumerable interface on the Grid class would allow LINQ queries to run against it. Do you think that would be valuable?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      Yup if you tend to use LINQ a lot that is definitely a good thing to add.

  • @mixuz91
    @mixuz91 Год назад +1

    So many times i run into errors because scripts dont compile.. I go over the video again and dont see how you solve it. Like how heatmapvisual was working in your first test and making grid generic. My scripts had tons of errors.. You solved these errors off "camera"?.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      What errors? Without knowing the text it's impossible to knw the cause. Maybe you just don't have a package installed?

  • @carlog1760
    @carlog1760 Год назад

    Hi, thanks for your precious tutorials! for some reason I cannot manage to print, on the grid of StringGridObject, letters and numbers on 2 lines... even putting
    in between... I tried to use Environment.NewLine but the result doesn't change... Any ideas?

  • @NotOfficiallySeanHD
    @NotOfficiallySeanHD 4 года назад +1

    So I followed everything in the tutorial just fine. but I don't get the black background? I've checked my Z and it's fine. I got the black background on the bool visual but for some reason not this one. It doesn't seem to be firing my updateHeatMapVisual part. but if I run "heatMapGeneric.SetGrid(grid);" it gives an error of:
    NullReferenceException: Object reference not set to an instance of an object
    How would one fix this?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Use Debug.Log to figure out exactly what object is set to null. Do you see a black object in the Scene view? If so then its something with the camera, if not then its something with the grid.

    • @olegentzsch3301
      @olegentzsch3301 4 года назад +3

      If u are still missing a solution. U might have just forgotten to assign your HeatMapVisual GameObject to the Serialized Field HeatMapVisual in the Unity Editor :)

    • @bosshauggin6920
      @bosshauggin6920 3 года назад

      @@olegentzsch3301 For anyone else running into this issue this resolved it for me! Thank you!

  • @AbuSalmanAngoli
    @AbuSalmanAngoli 4 года назад +1

    Hello there! I really apreciate your channel!
    One question: Why won't you use Unity's Tilemap fro your games?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      I prefer the flexibility of using my own and since its linked to my custom Grid System I can have the visual and the underlying logic sharing the same pattern.
      If you don't need any logic and just want visuals then Unitys tilemap is great

  • @collinfarrell9718
    @collinfarrell9718 4 года назад +1

    How are you able to access HeatMapGridObject in defined in the Testings script from HeatMapGenericVisual when you don't have a reference to Testing? Maybe it's because I'm using a different version of Unity but mine doesn't allow this.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      You mean the Grid using the Object class defined in Testing? The Grid receives a Generic type, it doesn't care where that type is defined, it just uses the object type it is given.

    • @collinfarrell9718
      @collinfarrell9718 4 года назад

      @@CodeMonkeyUnity Sorry, no I meant when writing code in HeatMapGenericVisual the editor wasn't recognizing HeatMapGridObject without first writing Testing.HeatMapGridObject. It makes sense that I had to do that I just though it was strange that your editor didn't force you to write "Testing." before "HeatMapGridObject" but mine did. Not really a problem just a curious observation. Thanks for the tutorial.

    • @foamtoaster9742
      @foamtoaster9742 3 года назад

      @@collinfarrell9718 In his code, the HeatMapGridObject class is outside of the testing class. I am guessing that in your code you wrote the HeatMapGridObject class inside the testing class which meant you had to write Testing.HeatMapGridObject

  • @JunneaXroc
    @JunneaXroc 5 лет назад

    Thank you for the excellent tutorials I've been following for a year now! One question: when you edit the code at 6:37 you get these wiggly lines under the OnGridValueChanged stuff and you don't show how you're fixing that, but still at 7:35, you run it without errors. When I follow along, I get this error: "Assets\GridMap\Scripts\HeatMapBoolVisual.cs(37,62): error CS0426: The type name 'OnGridValueChangedEventArgs' does not exist in the type 'Grid'". Line 37 is "private void Grid_OnGridValueChanged(object sender, Grid.OnGridValueChangedEventArgs e)
    " (because I like to put the { on a new line). Could you explain what is going on?

    • @JunneaXroc
      @JunneaXroc 5 лет назад

      ... never mind. If compared my code with yours and found that I also needed to put behind the Grid there. Missed that when following along. Sometimes it goes very fast! :-)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      Glad you found the solution!

    • @duckslayr
      @duckslayr 4 года назад +2

      @@CodeMonkeyUnity I was having this problem too, it makes it hard to follow when you fast forward all the code entry, you type ridiculously fast as it is, this is just impossible to catch all of at times.

    • @gabrieljt.3062
      @gabrieljt.3062 4 года назад

      @@JunneaXroc behind which Grid? I still can't fix that issue

    • @JunneaXroc
      @JunneaXroc 4 года назад

      @@gabrieljt.3062 Hmmm I don't think I remember for sure, but I think there's a reference to a grid somewhere that should have had behind it. It's been months and a global pandemic ago :-| What I do remember is that I ran my code against Code Monkeys and saw differences. Hope that helps.

  • @Ziron2008
    @Ziron2008 7 месяцев назад

    I did this one very different due to removing grid Events + LateUpdate from heatmap for performance. Even a constant bool check indefinitely isn't good in an update. I've learned a long time ago to avoid putting things in Update threads. That is how you achieve prime optimization. This is the main part that matters to show how to avoid this. You could technically still use an event for this part and just don't use the lateupdate for the other part I mentioned in the heatmap video. Either way, nothing in updates unless it's input logic. Even then, it would probably be better to use the new input system Unity created for this very reason.
    public void TriggerGridObjectChanged(int x, int y)
    {
    SetValue(x, y, gridArray[x, y]);
    }
    public HeatMapGridObject(Grid3D grid, int x, int y, HeatMapGenericVisual hmgv)
    {
    this.grid = grid;
    this.x = x;
    this.y = y;
    this.hmgv = hmgv;
    }
    public void AddValue(int addValue)
    {
    value = Mathf.Clamp(value + addValue, MIN, MAX);
    grid.TriggerGridObjectChanged(x, y);
    hmgv.UpdateHeatMapVisualGeneric();
    }

  • @jean-michel.houbre
    @jean-michel.houbre 5 лет назад +5

    Excellent video that showed me all the interest of generics, topic that I had left aside until then.
    New subscriber to your channel, I like the rhythm of your videos and your posted flow, which allows me to follow without making constantly pause or reverse.
    I think it's possible to use hexagonal grids, maybe even Unity provides something on these grids. Can you give me a track?
    Thank you.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      Thanks! Glad you like the videos!
      Hmm hexagonal grids are a very interesting concept, it seems like it would function exactly the same except for Odd row numbers you would shift the position to the side by half the cellSize. Could make for a very interesting video, I'll look into it, thanks!
      I believe Unity's Tilemap system already supports Hexagonal maps, so if you don't need special complex logic inside your tiles then that should do just fine.

    • @hypedoncoffee2884
      @hypedoncoffee2884 Год назад

      @@CodeMonkeyUnity Are you able to override the Unity Grid to add additional logic similar to your implementation? Did Unity add their grid after this video, and that's why you made your own implementation?

  • @MirjamvanM
    @MirjamvanM 4 года назад

    Just wondering.. is there a way to start the grid in the left upper corner? So 0,0 and as example to put the last 9,6 in the right bottom corner

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Sure, when you have all the math related to position, instead of doing +y do -y

  • @Adamthegeek70
    @Adamthegeek70 Год назад

    Which video has the events added to grid. I missed it.

  • @nkemer
    @nkemer 3 года назад +1

    Although great content and playlist, I think there is a continuity problem with this video. The code on the screen doesn't match with the code at the end of the previous video. If copy and paste then no problem but if you follow the code, it is not good. Full of error messages.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      Yes this "series" wasn't ever planned to be a series, I just made a Grid System then kept upgrading it over time so there are some things I made offscreen since I never planned on making this many videos on it.

  • @dewalderasmus6205
    @dewalderasmus6205 3 года назад

    I have done everything and it works perfectly until I came to 16:33 - 17:38
    I'm not sure what I did but it just shows that same as 16:33 I have no errors and it works but I don't get the heatmap visual. I went over it again and again and I feel like I'm missing something obvious but I'm not sure what it is. I also finished the tutorial and downloaded and looked over the files. for some reason evything works for me but the heatmap.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Is the heatmap behind the camera? Or maybe it's there but not changing color so it's always black?

    • @dewalderasmus6205
      @dewalderasmus6205 3 года назад

      @@CodeMonkeyUnity no not behind or always black just no color. At least I don't think it's behind because I can see the numbers fine when I enable Debug.log

    • @dewalderasmus6205
      @dewalderasmus6205 3 года назад

      for now I'm just going to continue on with the other tutorials and come back to this one when I have to implement the heat map. I started this journey because I wanted to place down building in a grid in game with prefabs. and unity's tile maps do not allow that. But now that I have the tile map I have a million other things I want to add to it later that I didn't even think about before.

    • @RRaiho
      @RRaiho 3 года назад +5

      @@dewalderasmus6205 Try to set the HeatMapGenericVisual in the start merthod
      HeatMapGenericVisual.SetGrid(grid);

    • @Grimbly44
      @Grimbly44 3 года назад +1

      @@RRaiho @Raiho Rai
      Had the same issue as Dewald, tried your soltion, works like a charm
      Thanks Raiho!
      Shoutout to Code monkey as well for all these tutorials!

  • @GameWithAshish58
    @GameWithAshish58 7 месяцев назад

    Hello, I've been working on developing a 2D farm system for my game, but I've hit a roadblock and could really use some guidance. I've been stuck on this for about a month now and would greatly appreciate any help or advice you can offer.

  • @themirlabs
    @themirlabs 5 лет назад +1

    im not sure if im backwards or something but that hardest thing for me so far has been building a mesh in code. i didn't get it that well and ended up using your script for it. i still dont get whats going on in there at all though.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      It is a bit confusing at first but when it clicks it all makes sense.
      Go slowly step by step and play around with the code.
      First try to make a simple untextured polygon. So manually position 3 vertices and 3 triangles. Then play around with the vertices to see the polygon change and play around with the triangles to see how if you put them counter clockwise the mesh will be facing backwards.
      Once you understand how a simple triangle works you know everything you need to expand upon it. A quad is just two triangles merged together.

  • @PureNrGG
    @PureNrGG 2 года назад

    Thanks for the wonderful tutorial! I do have a question however, why is this grid system better than the tile map system unity provides? I'm still a beginner to unity and have only made one Snake game haha so I still have much to learn. Thank you!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      The Tilemap system is meant for positioning visuals, whereas this system is meant for holding logic or any data in each grid position.
      For example later on in this series each Grid Object holds a reference to the Building that is placed on it or if it's empty. unitycodemonkey.com/video.php?v=dulosHPl82A
      The regular Tilemap system isn't meant to hold that kind of logic, only visuals.
      unitycodemonkey.com/search.php?q=grid

    • @PureNrGG
      @PureNrGG 2 года назад

      @@CodeMonkeyUnity Thanks for the response! This is so beyond my ability right now as I just started learning C# and Unity like 2 weeks ago. Luckily I know C and Java so I'm able to semi understand, but holy hell this is a lot haha but I'm learning so much from this tutorial!!

  • @Brian-fp8kp
    @Brian-fp8kp 3 года назад

    In the end of the video I had errors when trying to get a position out of grid. I also double checked with your code files. It seems that you forgot something? I fixed it with a nullcheck in the testing class though. Maybe there is a better solution? What do you suggest :)? if(Input.GetKeyDown(KeyCode.A)) { _grid.GetGridObject(GetMouseWorldPosition())?.AddLetter("A"); }
    if (Input.GetKeyDown(KeyCode.B)) { _grid.GetGridObject(GetMouseWorldPosition())?.AddLetter("B"); }

  • @jonahblack2000
    @jonahblack2000 2 года назад

    Question, I used these before while making a 2D game (pathfinding), but right now I am in a time crunch and want to use this grid system in 3D.
    I am trying to make a VR drawing "tablet" (A board) on which you draw "spell runes" and then it would compare with a library which I would create to see if there are any familiar runes and do the proper spell. I figured using your grid would be the best solution, as I can draw easily and add custom values to it, (for comparing afterwards).
    But I am not sure how to make the grid in 3D space and if it is possible to attach it to a game object (and if it would rotate with it). Or how to just spawn it in a certain direction.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      I've used this grid system in 3D in several videos, you mainly just need to change X,Y for X,Z unitycodemonkey.com/video.php?v=dulosHPl82A
      unitycodemonkey.com/video.php?v=gkCBCCKeais
      Although in your case it sounds like the spells are actually 2D or do you include depth in your spell drawing? Usually spell drawing is 2d only
      So for your use case I think it would be similar to how I did the pixel art system unitycodemonkey.com/video.php?v=Rfoyh3GOhOE

    • @jonahblack2000
      @jonahblack2000 2 года назад

      @@CodeMonkeyUnity the spell drawing grid is 2D (for simplicity for spell recognition).
      I just don't know how to move or rotate the 2D grid in a 3D enviroment (as in, could I attach the grid to a game object so the parent's transform affects the grid (so the grid would be facing the player).
      I know I could set the origin point to a empty GO which would be attached to the drawing tablet. But when the grid is created it uses world space, not local space, right?
      Also the grid itself is not a game object and therefore doesn't have a transform so it can't rotate I guess?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      ​@@jonahblack2000 You need to use some math to convert world positions in the board where you're drawing the spells. How are you detecting touches on the board? You have some location position where you touched on the board, use that to convert into a grid position. I'm not much of a mathematician, for me it's usually trial and error but that's where I'd start.

    • @jonahblack2000
      @jonahblack2000 2 года назад

      @@CodeMonkeyUnity Yeah I figured it would be something like that. I was hoping maybe you've done that already (If I manage that in a timely manner I will do that and send you the results, but for now I will "draw" using LineRenderers (cause I get info that I can compare 2 images with) as I am stressed for time.
      The way I would detect touches is by raycast hit/ collider collisions /onTriggerEnter.
      Alrighty then, thanks for your help

  • @KhongPh
    @KhongPh 26 дней назад

    Is the content in this clip a continuation of the clip "Grid System in Unity (Heatmap, Pathfinding, Building Area)" (ruclips.net/video/waEsGu--9P8/видео.html) or is there other content in between the clips? If there is content in between the two clips, can you tell me what kind of clip or content is in between?

  • @josephwilkins238
    @josephwilkins238 4 года назад

    My code still doesn't update the numbers the second time you ran it. I think it is something to do with the OnGridValueChanged object as it doesn't seem to get set at all during the project so it is left as null meaning the code won't run. It doesn't get mentioned that much in any of the videos so I have no clue what to do.

    • @josephwilkins238
      @josephwilkins238 4 года назад +1

      Ok. I figured out what to do there is a few lines of code at the bottom of setting up the grid this is the code for anyone with the same issue:
      OnGridValueChanged += (object sender, OnGridValueChangedEventArgs eventArgs) => {
      debugTextArray[eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y]?.ToString();
      };

    • @PleasureofaDream
      @PleasureofaDream 2 года назад

      I also ran into this issue but seem to have a different solution. I spent almost an hour debugging before realizing I forgot to assign the x and y values inside the constructors. This seems to be a common thing I forget when following along, to remember to assign inside any new variables added to the constructors.

  • @sonicherores
    @sonicherores 4 года назад +1

    Hello Again Love your tutorials but I run into a small problem with HeatMapGenericVisual When I replace the bool with HeatMapGridObject It freaks out telling me it does not exist I event went and compared with the project files and it still gives me an error telling me it HeatMapGridObject could not be found any idea where I messed up?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Sounds like you dont have the HeatMapGridObject class in your project, download the project files related to the Heat Map ruclips.net/video/mZzZXfySeFQ/видео.html

    • @sonicherores
      @sonicherores 4 года назад

      @@CodeMonkeyUnity Hello, I have got the HeatMapGridObject class inside my testing and I get no errors on it as well but when I try to get it on the generic visual part it states it doesn't exist which is where the confusion begins the class is set to public but I can still not get a reference to it sorry for the noob questions!

    • @paulcavey7494
      @paulcavey7494 4 года назад +2

      I am guessing you have not dragged the new generic heat map game object into the testing objects script. Or you have not set the grid in the start() of the testing script to set it. Eg heatMapGenericVisual.SetGrid(grid);

  • @Bmacorr
    @Bmacorr 3 года назад +1

    Hi CodeMonkey, thank you so much for creating these tutorials. I had a question about modifying this for a 3D project. I seem to have it working, but only the cubes along the the first X axis seem to have their values changed. I can tell that the other square values are getting their positions pulled correctly by the GetGridObject method when I click them, but it seems like the method for modifying the values on the grid cubes seems to still be based on an X,Y grid. I've been trying to figure out exactly where I need to modify it for my purposes and I think it's under the HeatMapVisual scripts and under the UpdateHeatMapVisual method, but I can't seem to figure it out. Any help would be appreciated.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +2

      Sounds like you may have an issue with either your Mouse world position or how you convert world positions into grid positions.
      Add a bunch of Debug.Logs to see what the code is doing
      You can inspect my Factory Sim game which is in 3D and uses this to see how it works ruclips.net/video/88cIVR4KI_Q/видео.html

    • @Bmacorr
      @Bmacorr 3 года назад

      @@CodeMonkeyUnity Thanks will do!

    • @Bmacorr
      @Bmacorr 3 года назад

      @@CodeMonkeyUnity Just an FYI. As suspected it was an error on my end where I had misspelled a reference to the Z axis, and I also forgot to move my 3D plain to the same height as the grid so that the raycast had something to hit. It works well now!

    • @rileybazan9747
      @rileybazan9747 2 года назад

      how did you make the heatmap 3d, did you render the meshes so they're were cubes? I tried that, and couldn't figure it out, so I ended up spawning cube objects instead.

  • @joyoussuccess
    @joyoussuccess 3 года назад +2

    Cool Heatmap in Unity is video #2 .. i think..., the playlist is out of order

  • @duskhammer8
    @duskhammer8 Год назад

    I have been going through this video and the others before this on the playlist for a while now and am not able to get the event to update that grid. so my question, if you happen to see this is, how is OnGridObjectChanged(this, new OnGridObjectChangedEventArgs { x = x, y = y }) actually updating the grid visuals? i have checked everything else and have confirmed that the value is actually updating. and i have put Debug.Logs() throughout the event code to make sure i am hitting all the methods. but i am just not able to get the visuals to update. and am not sure why newing up an OnGridObjectChangedEventArgs is changing the visuals at all. if you would be able to answer that would be a big help, Thank you! and also Thank you for making these tutorials in the first place. they are great!!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      The event is being listened on the debug logic
      On the Grid constructor, line 58 at 4:48, it listens to the event and updates the debug object

  • @2archarry
    @2archarry 7 месяцев назад

    I thought "what is the point of coding a class with generics if in the end the object managed by the grid must have a relathionship with the grid class". I understand we need to call the event when the object of the grid is changed.
    I would prefer to have a method like: public void performAction(int x, int y, Action gridObjectAction ){ } if the cordinates are valid then call gridObjectAction and finally call OnGridObjectChanged.
    Am I breaking single responsability principle with my sugestion?
    I felt discuraged when seeing that the TGridObject has to be coupled with Gird class.

    • @2archarry
      @2archarry 7 месяцев назад

      To me generics is "You can contain anything". But if the object can not be anything and has to honor some conditions then the generic might be a subtype like Grid where TGridObject : IInterfacesThatMakeTheGridObject has an atribute of grid type.
      I am just thinking out loud.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  7 месяцев назад +1

      Not sure I understand your question, the whole point of Generics is so you can reuse the same GridSystem with any kind of GridObject type.
      For example I've used this same Grid System for Pathfinding, for a City Builder, for a Factory Game, etc; all of those systems use the same GridSystem but different GridObjects since each have different data requirements
      unitycodemonkey.com/search.php?q=grid

    • @2archarry
      @2archarry 7 месяцев назад

      @@CodeMonkeyUnity Why the TGridObject has to know the Grid jus to call TriggerGridObjectChange?
      If so then TGridObject does not have to be a subtype of object.
      class A{
      private int state;

      public void IncreaseByOne(){
      state++;
      }
      }
      So the Grid.
      var grid = new Grid(Vector.Zero,(Grid g, int x, int y)=> new A());
      The Grid will not now when the internal state changes.
      What if orchestrate the internal change and call the event?
      class Grid{
      public void performAction(int x, int y, Action gridObjectAction ){
      //get the xy object
      var theXYObject = ...;
      gridObjectAction(theXYObject);
      //Then call the event
      OnGridObjectChange(new OnGridChangeEventArgs( ... ))
      }
      }

  • @mrmogelost6720
    @mrmogelost6720 3 года назад +9

    How come you've already created tutorials for almost everything I could wonder about??!!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +7

      That's my goal! With 400 videos I've already covered quite a bit, imagine when I get to 1000!

  • @TheIronicRaven
    @TheIronicRaven Год назад

    I am getting an error for the Func:
    Assets\Scripts\Grid.cs(16,84): error CS0246: The type or namespace name 'Func' could not be found (are you missing a using directive or an assembly reference?)
    No idea why that isn't working. Also not missing any assemblies that I know of. Why wouldn't this be workin?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      You need "using System;"

    • @TheIronicRaven
      @TheIronicRaven Год назад

      @@CodeMonkeyUnity 🤦‍♂️ it's always the simple stuff that gets me 😆 thanks a million! Love your vids!

    • @TheIronicRaven
      @TheIronicRaven Год назад

      @@CodeMonkeyUnity Are there more references you are using that aren't shown in the video? I was able to get along until the event system and then I am missing another assembly reference. It looks like your code has a lot of them, but they are cut off from the screen.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      Like what? This is the second video, did you watch the first grid system video?
      Also you can download the project files to look at all the source code

    • @TheIronicRaven
      @TheIronicRaven Год назад

      @@CodeMonkeyUnity hm, that is odd. I followed the first video and it worked perfectly! Not sure why this one is giving me reference errors.
      I'll see if I can download the files and root through them!

  • @atqamz
    @atqamz Год назад

    in my unity there's no MeshUtils.CreateEmptyMeshArrays method, what cause this happen?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      That's not a built in class, that's something I built. I don't remember which specific video I made that first, you can download the project files for this video or look at the mesh video unitycodemonkey.com/video.php?v=11c9rWRotJ8

  • @wasifalmeem4651
    @wasifalmeem4651 2 года назад

    i have a query can we use this grid system in UI to make a map and map it to our 3d world space?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      I'm not sure I understand your question, translate world positions into a UI map? Sure that could work.
      Alternatively you can just use the simple minimap method unitycodemonkey.com/video.php?v=kWhOMJMihC0

    • @wasifalmeem4651
      @wasifalmeem4651 2 года назад

      @@CodeMonkeyUnity im actually working on a 2d map similar to Decentralands map and i have used your grid building logic with the 3d environment and its working amazing now i wanna do the same thing but on UI in such a way that the sprite for Map is used to get the mouse current postion on that specific map sprite and from there map those coordinated to 3d world space

  • @futurewitness9162
    @futurewitness9162 2 года назад

    Hi, around the 17 minute mark where you change the grid type from bool to HeatMapGridObject I start getting errors. My grid was working perfectly up until then with the bool type, but when I try to switch to the HeatMapGridObject Grid I get a namespace error;
    CS0246 The type or namespace name 'HeatMapGridObject' could not be found (are you missing a using directive or an assembly reference?)
    I have no idea what to do about this or how to fix it. I'm completely stumped. I have noticed that HeatMaprGridObject also exists in the Testing Class, but am unsure if that affects anything as in your video you didn't change them (or show you changing them). The only things I did differently to you in the video is not rename all of the "GetValue"s, would that change anything? I also commented out the entirety of the first heatmap and bool scripts as they were causing clashes and were no longer being used as far as I could tell.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      It simply means you don't have anything in your project named "HeatMapGridObject"
      I made the heat map here ruclips.net/video/mZzZXfySeFQ/видео.html

    • @futurewitness9162
      @futurewitness9162 2 года назад

      @@CodeMonkeyUnity I've already completed that tutorial. I finished it with no errors and followed it up with this one. Should "HeatMapGridObject" be present somewhere in the script as a variable that I just missed? I've been comparing my scripts with yours in the utilities and been using that to fix my minor errors, but you don't have a HeatMap script in there so I have nothing to compare my HeatMap scripts to outside of the video.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      @@futurewitness9162 It's been a very long time since I made this video so I don't remember everything I did in it but that class was created in the Heat Map video and the error you're seeing is because it expects that class to be present in the project
      Alternatively you can download the project files for the videos later on in this playlist which will have the entire Grid class more polished ruclips.net/p/PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722

    • @steevdavis1421
      @steevdavis1421 2 года назад +1

      @@futurewitness9162 If it helps I was stuck on this too and just worked out the 2 things I had missed out. Your Testing script needs "heatMapGenericVisual.SetGrid(grid);" inside of Start() *and* your HeatMapGridObject class needs to be *outside* of the Testing class but in the Testing script. ie, make sure all your }s are fully closed off before you declare the HeatMapGridObject. Hope this makes sense and helps.

    • @PleasureofaDream
      @PleasureofaDream 2 года назад

      @@steevdavis1421 Thank you! This fixed it for me. Mine was inside the class!

  • @MrNintendeion
    @MrNintendeion 3 года назад

    I don't want to do any of the heatmap stuff as I'm trying to just implement A* into my turn based strategy game, this code seems unfollow-able though without having implemented all the heatmap stuff, can I follow this tutorial without doing the heatmap coding?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      The heatmap is just a visual so yes the grid works with or without it

  • @zodi4991
    @zodi4991 Год назад

    @CodeMonkeyUnity
    I've been trying to fix a problem I have with debugs and all but I cant get to find what cause this. When I click the text number doesnt update to its new value, however with debugs I found out that the value does change on the click. Do you know why?

    • @zodi4991
      @zodi4991 Год назад

      I've followed everything up to 16:35, and it seems to be the exact same as you however my text doesnt visually update to their new values and stay at 0

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад

      Are you sure you're modifying the correct object? Are you calling TriggerGridObjectChanged with the correct XY?
      Add DEbug.Log's on every step of the way to see which part is failing, maybe you're not changing the right XY, maybe the debugs are not updating, maybe you're not correctly getting the ToString();

  • @devnest4623
    @devnest4623 3 года назад +1

    i like the informative and unique information you deliver not many does work stuff like this but i d argue again the quality of the editing.
    if you aren't well advanced you will totally get lost. so many important details get so lost by the editing i assume

  • @abdou023
    @abdou023 3 года назад

    My current project doesn't show the value on the map when I click on a tile. I just need to show the value without all the heatmap, event triggering stuff.
    Is there a simpler way?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      Are you working on a 3D game? The method for getting the mouse position is different ruclips.net/video/0jTPKz3ga4w/видео.html

    • @abdou023
      @abdou023 3 года назад

      @@CodeMonkeyUnity
      Thank you for replying.
      There is no problem with the mouse position. I was just asking if there is a simpler way to display the value rather than using the event handler or basically the entire heatmap section of this tutorial.

  • @goose4878
    @goose4878 2 года назад

    I downloaded the Codemonky Utilities but it's missing MeshUtils. Anyone know why? I don't want to learn mesh right now as it's a lot to learn. I'm stuck on this now.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +1

      The MeshUtils aren't part of the regular utilities, I made those in a separate mesh based video although I don't remember exactly which one.
      If you download the project files for a recent project it will be there, for example this one unitycodemonkey.com/video.php?v=XqEBu3un1ik

  • @Ryan-ww7un
    @Ryan-ww7un 2 года назад

    There's already a grid class in Unity. How did you handle the conflict?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад +2

      That built in class does not support generics so as soon as you implement generics there's no more conflict

  • @Kondensatorr
    @Kondensatorr 4 года назад

    How can I get just the generic grid from package?

  • @MalikenGD
    @MalikenGD 5 лет назад

    Bit of a programming noob here, but do generics work with DOTS/Burst?

  • @theashbot4097
    @theashbot4097 2 года назад

    you have the videos are out of order. you have this as the second video in the sires, but you say we should watch the 4th video in the series before we fallow this one. so I think you should put this in a better order. I apresheat all the work you put into these videos thank you.

  • @MrGhettoGurke
    @MrGhettoGurke 2 года назад

    Hey CodeMonkey, really nice video :)
    But i have one question. Instead of creating a reference to the grid in the HeatMapObject, i did this:
    if (gridTestObject != null) {
    {
    gridTestObject.AddValue(5);
    grid.SetGridObject(gridTestObject.x, gridTestObject.y, gridTestObject);
    }
    }
    This works, but is this a valid solution?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      Sure, but what exactly are you doing? It seems like you're not creating all the grid objects during construction but rather only when setting the value. So all grid objects will be null until they have a value in them, is that your goal?
      It works but it seems like a needlessly confusing way to do it.

    • @MrGhettoGurke
      @MrGhettoGurke 2 года назад

      @@CodeMonkeyUnity I tried to encapsulate the Grid from the TestObject. But nvm, i figured out how to use the event system to raise an event, and than listen to that event in the grid. But thank you for the fast response :)
      But now i have an other question. Can i transform the grid into an isometric grid?

  • @edubyou
    @edubyou Год назад

    Why is this second in the playlist when it uses so much Heatmap? that not for two more episodes - its really odd. Great instructions but not explaining where stuff came from is hard to piece together. I'm doing mine in a 3D environment and I intend to use some physics so I had to change y for z but I might just have hit a wall as in comes vector2's oh shit.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +1

      That's because this series of videos wasn't planned ahead of time, I just started building a GridSystem and kept building upon it, so some things are out of order.
      The GridBuildingSystem video has downloadable project files and is in 3D unitycodemonkey.com/video.php?v=dulosHPl82A

    • @edubyou
      @edubyou Год назад

      @@CodeMonkeyUnity thanks so much. I kept watching through to late in the series and things are making a lot of sense now. Good idea to just watch these for the approach and then play with it after in Unity. Great content good sir.

  • @AmgedAlfakih
    @AmgedAlfakih 7 месяцев назад

    So how to make the grid folow the parent rotation??

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  7 месяцев назад +1

      This grid doesn't have the concept of a parent, it just has an origin position.
      Although sure you could make the origin the same as some kind of parent object, and use some math to apply rotation to all the grid positions based on the parent

    • @AmgedAlfakih
      @AmgedAlfakih 7 месяцев назад

      @@CodeMonkeyUnity so what is the calculation for this, any idea or article??

  • @saif0316
    @saif0316 4 года назад +4

    I have to watch these at .25 speed to understand 😅

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +2

      Yup, take your time! Remember that it took me a long time to learn all of this, certainly longer than the video length.

  • @hoxtober9879
    @hoxtober9879 4 года назад

    I can't get access to the Utils, cause e-mail verification is not working at the web site. Anyone had such problem? Any advice could help!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Check your spam folder

    • @hoxtober9879
      @hoxtober9879 4 года назад

      @@CodeMonkeyUnity Thx, mail was storde in another section :/

  • @madhackademy3558
    @madhackademy3558 4 года назад

    i must say with only 3 years in coding the "Func createGridObject" blow up my mind and i honeslty would work with a simple struct for one purpose in my case the path finding. I think it could work too . I m wrong i m right i dont know. Now i feel like i m in a sand box and playing with my poop. Dont get me wrong this is rly good stuff. But i think with this grid system i will not be able to adapt in my use case or Sadly follow with the DOTS or ECS version you made. I suppose your chanel is out of my league. See ya

  • @밥도둑-l5j
    @밥도둑-l5j 5 лет назад

    Love it! can you make a video about produceral animation tutorial? i'm really waiting for that!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      That is a very interesting topic that I'd definitely love to explore at some point

  • @twobits7310
    @twobits7310 4 года назад

    I am a bit confuse about this decoupling and dependency thing(I listen about decoupling and dpd but i never implement these concepts). Otherwise am good programmer and i understand every single line of your code.

  • @Robster881
    @Robster881 2 года назад +1

    You really need to re-order these. I'm trying to follow along and you start talking about things in the code you've not covered yet in the playlist.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      This series wasn't planned ahead from the start, I just started building the grid and improving upon it. So there's no 100% step by step path like in my courses

  • @blameyourm8519
    @blameyourm8519 3 года назад

    What is heatmap for in games?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      You can use it to display stats in a map, like where players get the most kills
      Or use it to build a tool to see where your player clicks
      The Heatmap is just a visual, it's up to you to decide what data it uses.

  • @Adkinsy85
    @Adkinsy85 5 лет назад +1

    You are so cool 😎👌

  • @lolocustlol
    @lolocustlol 3 года назад

    Hey i love your tutorials, just my opinion but it would have been easier to follow for me if you had done the letter and numbers example first and then the heat map

  • @juliendev2191
    @juliendev2191 4 года назад

    I know the video is really old already, but why don't I just make a grid of structs ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Because most of the times it's much more useful to store an object rather than simple data.

    • @juliendev2191
      @juliendev2191 4 года назад

      @@CodeMonkeyUnity oh, okay, what about holding a scriptable object ? I'm new to unity so I'm trying to figure out some clean ways of coding things in this engine :)

  • @salehsdlkfjslk4959
    @salehsdlkfjslk4959 2 года назад

    what is override?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 года назад

      You "replace" the virtual function in the base class

  • @joshcarstens8982
    @joshcarstens8982 11 месяцев назад

    Hey CM, thanks for the video! I've tried to adjust the code for 3D and so far it was working fine but, after 16:16 only the first node seems to work when clicking on it. I'm using this code in my Testing script's Update function to set the position of the clicked node:
    private void Update()
    {
    if(Input.GetMouseButtonUp(0))
    {
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out RaycastHit rayCastHit, 100, Ground))
    {
    if (rayCastHit.collider != null)
    {
    if (rayCastHit.collider.CompareTag("GroundTile"))
    {
    string tileName = rayCastHit.transform.name;
    var tileCords = tileName.Split(',');
    int tileCordX = int.Parse(tileCords[0]);
    int tileCordZ = int.Parse(tileCords[1]);
    Vector3 pos = new Vector3(tileCordX, 0.75f, tileCordZ);
    HeatMapGridObject heatMapGridObject = grid.GetGridObject(pos);
    if(heatMapGridObject != null)
    {
    heatMapGridObject.AddValue(5);
    }
    }
    }
    }
    }
    }
    I'm just casting the tutorial grid over a "grid" of 3D objects that are aligned in the same manner.
    Do you perhaps have any idea what I might be doing wrong?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  11 месяцев назад +1

      Add some Debug.Log to see at what point your code is stopping
      Maybe you only added a collider to one node? Maybe only one has the GroundTile tag?

    • @joshcarstens8982
      @joshcarstens8982 11 месяцев назад

      Thanks for the response! I wasn't setting the x,z in the public HeatMapGridObject(Grid grid, int x, int z) section, only the grid... Now I feel really dumb. @@CodeMonkeyUnity

  • @micaiahstevens8840
    @micaiahstevens8840 5 лет назад

    Was a bit confused, thought you had to define your custom type; in this case TGridObject.
    However it seems the Generic knows since it starts with T or something you are creating a Generic. I was mistaken somehow. Its not QUITE clear in the video how you came up with this Variable, name type object thingy!

    • @micaiahstevens8840
      @micaiahstevens8840 5 лет назад

      Might try and make a link to a XY grid and a XZ grid, its always frustrating when people make a screen grid vs a ground grid. I get why they would do it, but in a 3D it doesn't make much sense. (NOTHING to say that this Screen Grid facing the screen isn't helpful or useful especially in your games.) I wish was some sort of projection matrix, or way to slice the ground grid, and use a single Z as your Y in your Screen grid.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +3

      You just define the name for the type, it can be anything you want, normal naming convention is to start generics names with T
      Putting it inside < > is what tells it that it's a generic.

    • @micaiahstevens8840
      @micaiahstevens8840 5 лет назад

      Thanks very much. Did over an hour and a half reply video, BUT ended up writing the TileGeneric, probably should not steal your thunder. I imagine your is going to be MUCH flashier than mine. Although talked about a basic Tile Editor as well.

  • @saif0316
    @saif0316 4 года назад +2

    I just wanna make an A* pathing algorithm 😭

    • @xxbongobazookaxx7170
      @xxbongobazookaxx7170 3 года назад

      Same, I've done it in python ages ago but C# is so confusing to me still

  • @oleksiiliaskovskyi5381
    @oleksiiliaskovskyi5381 5 лет назад +3

    Pleaseee, don't use speeding up. Its so confusing when you can't understand what's going on and when code part is huge I get lost with your tutorial.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      You can pause the video at any time and download the completed Project files from the website.

    • @tgdwarf
      @tgdwarf 3 года назад

      @@CodeMonkeyUnity Its a good thing that you do, keep the tempo high for when you just want the explanation of the code, but don't the specifics, as you say, can always download or pause to see it.

  • @jirlon
    @jirlon Год назад

    For me to understand a specific video, I need to travel between several videos. I would like to learn the content of video 12, but he recommends watching video 1 and 2. In video 2 he recommends watching video 4 first, all of this is a huge mess.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Год назад +1

      This "series" wasn't planned ahead of time, I just started building a grid system and then kept building on top of it, and then some applications (like the Building System and Heat Map) are forks and not sequels so yeah it can be a bit messy.
      If you're looking for a step by step guide then I recommend you follow my TBS course, in there I use a Grid System like this one ruclips.net/video/QVdKnKfgOJY/видео.html

    • @TheGreenLing
      @TheGreenLing Год назад

      @@CodeMonkeyUnity Thanks for linking to this very helpful!