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!
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'
@@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.
@@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)
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.
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.
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.
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.
@@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!
@@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?
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!
@@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;
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!
@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?
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!
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.
@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?
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
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'
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.
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 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.
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.
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.
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
@@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.
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.
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.
@@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 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 $$$.
@@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?
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); } }
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.
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.
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?
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
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".
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);
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.
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?
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
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.
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 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.
@@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.
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
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!
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
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); } } }
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?
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?
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.
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
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
@@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?
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.
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.
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)"?
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"?.
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?
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?
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.
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 :)
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
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.
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.
@@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.
@@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
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?
... 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 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 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.
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(); }
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.
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.
@@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?
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.
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.
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 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
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 @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!
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.
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.
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.
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!
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
@@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!!
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"); }
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.
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
@@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?
@@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.
@@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
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?
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.
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(); };
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.
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?
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
@@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!
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);
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.
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
@@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!
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.
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!!
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.
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.
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
@@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( ... )) } }
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 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 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!
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
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
@@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
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 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.
@@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
@@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.
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 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?
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
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();
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
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 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.
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.
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
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.
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?
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.
@@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?
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.
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
@@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.
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
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
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.
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
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.
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
@@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 :)
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?
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
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!
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.
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.
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.
@@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.
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.
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
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!
how can I get your code from your package so I can change it a little bit?
@@lyricsmaker-poplyricsmaker1183 There's a link in the description
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'
@@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.
@@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)
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.
Yes thanks
Being able to pass functions as a parameter is so handy. As always, super amazing video filled with so much knowledge!
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.
Being able to use any type is fantastic
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.
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.
@@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!
@@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?
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!
@@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;
OMG i made by this amazing tutorial about half a day, and now spend another half to understand all
Great job on taking your time to truly learn! Keep at it!
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!
Excellent presentation of Lambda use, when you havent done it in a while its a great refresher
@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?
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!
Yeah for a Heatmap adding a little validation to the values would be a good idea.
I'm glad you found the video helpful!
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.
Sounds like you're using 2 different types, one just HeatMapGridObject and another one named the same but inside another class named Test
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
@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?
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
Func exists inside the System namespace so it's just because you don't have "using System;" on top
@@CodeMonkeyUnity So stupid issue... I should have notice that, anyway TY, and for great tutorials too!
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'
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.
@@aldenmauro2227 Thanks man
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.
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.
@@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.
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.
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.
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
@@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.
@@magictimm4090 how did you do it ?
@@HorizoneMeNol Sorry, cannot find the code
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.
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.
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.
@@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.
@@lens3973 What?
@@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 $$$.
@@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?
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);
}
}
thanks for this. i've bought your course too!
I hope you like it! Thanks!
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.
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.
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?
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
@@CodeMonkeyUnity Amazing. You are just a chest of treasures.
Excellent contents! Thank you!
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".
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);
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.
Just thought about world generation earlier that day, nice 👌
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
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?
The type or namespace name 'Func' could not be found (are you missing a using directive or an assembly reference?), How to fix it?
On the top of your file add:
using System;
@@CodeMonkeyUnity Thank you!!
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
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.
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?
Does it turn from False to True? Use Debug.Log to verify that you're calculating the correct mouse position and grid position
@@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.
@@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.
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
Amazing content! Thank you very much!
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!
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
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);
}
}
}
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?
Sounds like your code is trying to use the built-in Unity Grid instead of the one created in this video
@@CodeMonkeyUnity Wow thanks! I didn't expect a reply. This video is pretty old.
I was able to fix the error by replacing "Grid grid = new Grid(PARAMS);" with "Grid grid = new Grid(PARAMS);"
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?
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.
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
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
@@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?
@@CodeMonkeyUnity can you please make video on this
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.
The default shortcut for Rename is Ctrl + R + R
It renames all instances of the selected function/class/variable
@@CodeMonkeyUnity May be the most valuable thing I've learnt so far! Love your work
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.
Looks like you're passing in the Grid reference as a parameter to GetGridObject instead of the position
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)"?
Yup it's the Tilemap video ruclips.net/video/gD5EQyt7VPk/видео.html
5:46 I changed everything but after change to Generics i got error in testing class
What error message are you receiving? If you've already solved the problem, nevermind!
Could you please elaborate if I was to add grid component to my terrain how can this make it easier then this approach ?
Implementing the IEnumerable interface on the Grid class would allow LINQ queries to run against it. Do you think that would be valuable?
Yup if you tend to use LINQ a lot that is definitely a good thing to add.
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"?.
What errors? Without knowing the text it's impossible to knw the cause. Maybe you just don't have a package installed?
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?
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?
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.
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 :)
@@olegentzsch3301 For anyone else running into this issue this resolved it for me! Thank you!
Hello there! I really apreciate your channel!
One question: Why won't you use Unity's Tilemap fro your games?
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
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.
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.
@@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.
@@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
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?
... 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! :-)
Glad you found the solution!
@@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.
@@JunneaXroc behind which Grid? I still can't fix that issue
@@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.
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();
}
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.
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.
@@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?
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
Sure, when you have all the math related to position, instead of doing +y do -y
Which video has the events added to grid. I missed it.
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.
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.
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.
Is the heatmap behind the camera? Or maybe it's there but not changing color so it's always black?
@@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
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.
@@dewalderasmus6205 Try to set the HeatMapGenericVisual in the start merthod
HeatMapGenericVisual.SetGrid(grid);
@@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!
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.
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.
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.
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!
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
@@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!!
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"); }
Yup a simple null check works
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.
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
@@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?
@@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.
@@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
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?
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.
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();
};
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.
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?
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
@@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!
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);
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.
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
@@CodeMonkeyUnity Thanks will do!
@@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!
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.
Cool Heatmap in Unity is video #2 .. i think..., the playlist is out of order
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!!
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
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.
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.
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
@@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( ... ))
}
}
How come you've already created tutorials for almost everything I could wonder about??!!
That's my goal! With 400 videos I've already covered quite a bit, imagine when I get to 1000!
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?
You need "using System;"
@@CodeMonkeyUnity 🤦♂️ it's always the simple stuff that gets me 😆 thanks a million! Love your vids!
@@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.
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
@@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!
in my unity there's no MeshUtils.CreateEmptyMeshArrays method, what cause this happen?
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
i have a query can we use this grid system in UI to make a map and map it to our 3d world space?
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
@@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
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.
It simply means you don't have anything in your project named "HeatMapGridObject"
I made the heat map here ruclips.net/video/mZzZXfySeFQ/видео.html
@@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.
@@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
@@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.
@@steevdavis1421 Thank you! This fixed it for me. Mine was inside the class!
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?
The heatmap is just a visual so yes the grid works with or without it
@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?
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
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();
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
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?
Are you working on a 3D game? The method for getting the mouse position is different ruclips.net/video/0jTPKz3ga4w/видео.html
@@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.
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.
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
There's already a grid class in Unity. How did you handle the conflict?
That built in class does not support generics so as soon as you implement generics there's no more conflict
How can I get just the generic grid from package?
Bit of a programming noob here, but do generics work with DOTS/Burst?
Yup it should work just fine.
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.
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?
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.
@@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?
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.
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
@@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.
So how to make the grid folow the parent rotation??
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
@@CodeMonkeyUnity so what is the calculation for this, any idea or article??
I have to watch these at .25 speed to understand 😅
Yup, take your time! Remember that it took me a long time to learn all of this, certainly longer than the video length.
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!
Check your spam folder
@@CodeMonkeyUnity Thx, mail was storde in another section :/
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
Love it! can you make a video about produceral animation tutorial? i'm really waiting for that!
That is a very interesting topic that I'd definitely love to explore at some point
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.
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.
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
What is heatmap for in games?
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.
You are so cool 😎👌
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
I know the video is really old already, but why don't I just make a grid of structs ?
Because most of the times it's much more useful to store an object rather than simple data.
@@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 :)
what is override?
You "replace" the virtual function in the base class
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?
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?
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
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!
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.
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.
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.
I just wanna make an A* pathing algorithm 😭
Same, I've done it in python ages ago but C# is so confusing to me still
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.
You can pause the video at any time and download the completed Project files from the website.
@@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.
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.
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
@@CodeMonkeyUnity Thanks for linking to this very helpful!