Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Grid Framework [scripting and editor plugins]

Discussion in 'Assets and Asset Store' started by hiphish, Jul 24, 2012.

  1. DrEvizan

    DrEvizan

    Joined:
    Jun 26, 2017
    Posts:
    6
    Thank you. In retrospect that answer was pretty obvious but thanks for leading me there anyway!
     
    hiphish likes this.
  2. VectorNector

    VectorNector

    Joined:
    May 22, 2013
    Posts:
    62
    Hi,

    I’m messing with the sliding puzzle example and I want to add another axis to the game’s mechanics so that the blocks can slide on all 3 axises. What do you suggest doing?

    Thank you!
     
  3. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Hello,

    The code should work the same, the tricky task will be to actually come up with a good way of moving blocks in a 3D environment using 2D controls. Moving blocks by itself has nothing to do with grids, so I would suggest that you first find a way of moving blocks free-form (no snapping), and once you have that working you can apply the snapping code from the 2D puzzle and it should work the same.
     
    VectorNector likes this.
  4. VectorNector

    VectorNector

    Joined:
    May 22, 2013
    Posts:
    62
    Hi HiPhish,

    I see what you're saying. I was thinking about using an isometric view to make everything work. Now I understand that it's about getting the controls down first.

    I appreciate your help. Thank you so much!
     
    hiphish likes this.
  5. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    Hi, I just upgraded my app to URP. I’m using a parallelpiped with the GridFramework/DefaultShader. The mainCamera is equipped with a Grid Camera. The plugin was working with no issues before the update to URP. But after the update, the grid is no longer showing during runtime.
    How should I modify the defaultShader to work with URP or perhaps is there a specific setting to make it?

    Edit: Visiting the sample scenes, none of the grid lines are appearing either. Grids still appear in the scene/editor mode.
     
    Last edited: Sep 5, 2020
  6. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    I think this is the source of the problem:
    https://docs.unity3d.com/Packages/c...l@8.2/manual/InstallingAndConfiguringURP.html

    The lines do not belong to any mesh, they are generated on the fly during runtime and rendered in the OnPostRender method. You could either wait for URP to implement post processing effects, or use Grid Framework to generate a mesh at runtime and render that one. If you want to use the latter, it's not trivial, but you can contact me via PM and we can work out the necessary code. Generating a mesh from data is also how Vectrosity renders vector lines, so it's not an outlandish idea.
     
  7. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    Thank you for the update Hiphish. I’d like a solution, but I think it would better serve both our times to wait for URP to get to that stage instead of creating a bandaid fix.

    For now, I’ll just roll back the URP updates. Hopefully they fix post processing first before they make URP the standard.
     
    hiphish likes this.
  8. ssssxxxxdddd

    ssssxxxxdddd

    Joined:
    Sep 21, 2020
    Posts:
    1
    Hi, do you think this would work for making an oblique/cabinet projection 2d game? I am struggling to find any way to change my grid from something other than iso/hex :(
     
  9. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Are you using a 2D game project or a 3D game project?
     
  10. Yagolov

    Yagolov

    Joined:
    May 25, 2020
    Posts:
    2
    Hello!

    I am not a coder and I bought the asset yesterday because it supports PlayMaker.
    I have read the information, watched the videos on youtube and went through few pages of the forum and...
    I still can not figure it out how to make the conection between the Grid and the Game objects.
    I am sorry if it is really wide my questiion... but after lots of hours trying my best I think it would be great if someone could throw me some light.

    What I want to achieve is creating an hexagonal grid (I already have created it and added the Scripts and the Mesh collider) and then placing different game objects that snaps in the already created grid. I really would appreciate if you/someone could help me out in this noobish question about how I should approach this.

    The concept it is similar to Chess. A grid with different objects that moves within the grid using mouse clicks.

    Thank you !!
     
  11. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Hello.

    You don't make a direct connection between your objects and the grid. What you do instead is something like this:

    • Get the world position of your object (store inside a Vector3 variable)
    • Convert it to grid coordinates (another Vector3 variable)
    • Do some math on it, such as rounding the individual values if you want to snap an object, or add another vector if you want to move the object; the result is another Vector3 coordinates
    • Conver the (new) grid coordinates back to world coordinates
    • Move your objec to the new world coordinates.
    So if you had a chess game and you want to move the bishop two fields diagonally, you would take the bishop's grid position, add the vector (2, 2, 0) to it, convert the result to world coordinates, and animate the bishop's movement.

    This is the basic pattern of using Grid Framework for moving objects in the world. When you write code you can wrap those five steps behind one method to hide the complexity, not sure how Playmaker handles complexsity. I hope my explanation makes sense to you. Let me know if it doesn't.
     
  12. Yagolov

    Yagolov

    Joined:
    May 25, 2020
    Posts:
    2
    Hello,

    Thanks a lot!
    I struggled but you provided me the guides that I really needed.
    Much appreciated!
     
    hiphish likes this.
  13. lsotero

    lsotero

    Joined:
    Apr 21, 2018
    Posts:
    2
    Hi there, I have searched quite a lot and haven't found a way to do so. I know it uses GL to draw at runtime but I really don't have much knowledge on the rendering part, but it doesn't matter what I do, it always draws on top of everything? I'm trying to mix it with sprites and it's ALWAYS on top of every single sprite I place in, doesn't matter what I try to change, is there a way to actually use the renderer like that? I think I even remember seeing something like this draws Lines and not Surfaces, but do I require it to be a surface in order to Z sort them for sprites?
     
  14. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Hello,

    Can you please provide me some more information? Are you using a 2D or a 3D project? Can you please provide a screenshot (PM me if you don't want it public)? I first need to reproduce the issue on my end.
     
  15. lsotero

    lsotero

    Joined:
    Apr 21, 2018
    Posts:
    2
    I sent you a pm
     
  16. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Plans for Grid Framework 3.0

    I intend to release a new major update which will address among other things the grid rendering system. It has been almost five years since the release of version 2.0, and Unity has changed quite a lot in this time. Some of those changes, in particular the introduction of sprites, need to be accounted for in Grid Framework.

    This will be a major update which breaks backwards compatibility. Some breaks are necessary, some will simply be me cleaning up minor bumps while I'm at it. But all in all I expect the changes to be small, much smaller than between 1.0 and 2.0.

    The upgrade will be free for existing customers since it will be basically just a maintenance release.

    Upcoming changes
    Rendering grids
    Unity is a 3D game engine, it primarily renders 3D game models. There is an escape hatch provided by the GL class, but lines drawn that way appear on top of sprites, even if the sprite is in front of the grid in the scene. This is simply not acceptable, but this way of rendering grids has big advantage over any alternative approach, so getting rid of it is not an option either.

    Let's take a step back for a moment. C# is an object-oriented language, and the point of object-oriented programming is interfaces and messages: the program consists of a graph of objects which communicate among each other by sending messages. The important part is not what class an object has, the important part is what public interface an object exposes, which messages it can receive. We can at runtime swap out one object for another object as long as both expose the same interface, regardless of how they implement that interface.

    Following that logic, why should there be only one way of rendering a grid? I wish to expose a generic rendering interface and allow users to plug in their own backend of choice. Some default implementations will be included, but users will be able to create their own implementations as well. Here are my planned implementations so far:

    • The already existing GL implementation
    • A new implementation which generates a mesh with Lines topology
    • A Vectrosity backend, which will be basically the already included Vectrosity support, but rewritten
    Different backends have different strengths and weaknesses. For example, Unity renders the lines of a mesh with Lines topology always at the same width, and there is nothing I can do about that, but in return you can use all the shader features of Unity and lines will appear behind grids. For some people that might be exactly what they need.

    The main change between version 1.0 and 2.0 was breaking the huge grid classes into small grid classes and separate render classes. This has proven to have been a good choice and has allowed users to create their own grids very easily. I know one customer who has created a custom grid which looks like the wires of a guitar (the horizontal lines are not parallel and the distance between vertical lines keeps increasing). I hope that this change will empower users similarly.

    No more included examples
    Grid Framework comes with a number of examples included to get you started. When I had originally submitted Grid Framework to the Unity Asset Store I was asked to provide an example or two because it wasn't really clear what my asset was doing. Since then the number of examples and their sophistication has grown, and Grid Framework has been established.

    Bundling these examples nowadays just adds bloat to people's projects. Sure, you can just delete them (they are all in one common directory), but then you have to do so after each update. For 3.0 I want to move the examples to a separate project that can be hosted in public. It would also allow people to see the API in action before they make a purchase.

    Minimum Unity version required
    I have not yet settled on a definitive version, but I will certainly increase the requirements. This will allow me to make use of more recent C# features and keep the code leaner.

    Time frame
    I do not have any estimate on when 3.0 will be released. The changes to the code are not large, but I have to get the API right the first time. How should the user hook up the rendering backend to the engine? Should I allow multiple backends at the same time? Where should newly created GameObjects and components be added to the scene?

    I hope to release 3.0 somewhere during the first quarter of 2021, but time will tell.
     
    stansison and SirStompsalot like this.
  17. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    I came to check here to see if there would be news about URP compatibility. This update sounds amazing. Looking forward to it.
     
    hiphish likes this.
  18. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Version 3 reaching feature parity with version 2

     
  19. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Mesh-based rendering
     
  20. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,409
  21. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    I am aware of Linefy and I would like to support it eventually, just not at launch. The possibility of supporting Linefy (and any other future framework) is why I want to clean up the interface and make it as easy as possible to hook up anything. But I want to keep the scope of the initial release of 3.0 focused on what we already have so I can release it sooner rather than later.
     
  22. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Vectrosity rendering backend
     

    Attached Files:

    EmeralLotus likes this.
  23. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,409
  24. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Embracing the Unity package system
     
  25. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Vectrosity support as a package
     
  26. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Git packages or embedded packages? Yes.
     
  27. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Playmaker actions overhaul
     
  28. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Playmaker samples
     
    crafTDev likes this.
  29. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Align panel as a package
     
  30. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Homestrech
     
  31. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Change of plans regarding Unity3D package
     
  32. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Now we wait
     
    florianveltman likes this.
  33. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Grid Framework version 3.0.0 released
     
  34. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    31
    Hi,

    I am trying to get this working with Vectrocity but I am just getting compile errors.

    I have imported the latest versions of Vectrocity, the grid framework and the Vectrocity backend stuff from your git site by adding it as a dependency and importing through the unity package manager. I am now getting three build errors stating that the VectrocityBackend.cs file is unable to recognise the Vectrocity namespace which is true it can't.

    I am currently using Unity 2021.2.7f1

    Any ideas on how to solve this?
     

    Attached Files:

  35. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Hello,

    Does the included sample scene work for you? You can import it from your Unity Package Manager window, see the attached screenshot. If it does not there might be something wrong with how the Asset Store has packaged Grid Framework because it works on my machine. There should be a file in your Assets folder under com.hiphish.grid-framework/Runtime/ named com.hiphish.grid-framework.Runtime.asmdef with the following contents:

    Code (csharp):
    1. {
    2.     "name": "com.hiphish.grid-framework",
    3.     "rootNamespace": "GridFramework",
    4.     "references": [],
    5.     "includePlatforms": [],
    6.     "excludePlatforms": [],
    7.     "allowUnsafeCode": false,
    8.     "overrideReferences": false,
    9.     "precompiledReferences": [],
    10.     "autoReferenced": true,
    11.     "defineConstraints": [],
    12.     "versionDefines": [],
    13.     "noEngineReferences": false
    14. }
    Does this file exist on your machine?
     

    Attached Files:

  36. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    31
    Hi, Thanks for getting back to me.

    The file you reference is present and contains the above. The sample projects appear OK although I am currently in a URP context which I don't think is supported so everything renders in pink.

    I am trying to get the Vectrosity back end working to get around the aparant lack of URP support (unless I am missing something and there is some update script I need to run or something). The problem manifests when I import the Vectrosity backend from your git and I get the compiler issues so it feels to me like your backend project config doesn't know where to look for Vectrosity.

    For reference the VectrosityBackend asmdef file looks like:

    Code (CSharp):
    1. {
    2.     "name": "com.hiphish.grid-framework.vectrosity.Runtime",
    3.     "rootNamespace": "GridFramework",
    4.     "references": [
    5.         "com.hiphish.grid-framework"
    6.     ],
    7.     "includePlatforms": [],
    8.     "excludePlatforms": [],
    9.     "allowUnsafeCode": false,
    10.     "overrideReferences": false,
    11.     "precompiledReferences": [],
    12.     "autoReferenced": true,
    13.     "defineConstraints": [],
    14.     "versionDefines": [],
    15.     "noEngineReferences": false
    16. }
    Any thoughts?

    Edit: Just to make sure there wasn't anything clouding the issues here I just created a brand new standard 3D project in 2021.2.7f1 using the inbuilt render pipeline, imported only Vectrosity, Grid Framework V3 and the Vectrosity backend in that order and it immediately gave the same issue.

    Also just tried it in Unity 2020.3.25f1 to see if this was something to do specifically with 2021. Same issue.

    I have been cloning your Vectrosity back end using the URL from the main branch (https://gitlab.com/HiPhish/grid-framework-vectrosity.git) as the one specified in your documentation (https://gitlab.com/hiphish/grid-framework-3-vectrosity.git#v3.0.0) appears invalid:

    Code (CSharp):
    1. [Package Manager Window] Cannot perform upm operation: Unable to add package [https://gitlab.com/hiphish/grid-framework-3-vectrosity.git#v3.0.0]:
    2.   Error when executing git command. remote: The project you were looking for could not be found or you don't have permission to view it.
    3.  fatal: repository 'https://gitlab.com/hiphish/grid-framework-3-vectrosity.git/' not found
    4. [NotFound].
    5. UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
     
    Last edited: Jan 7, 2022
  37. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    The assembly definition looks correct. Where have you imported Vectrosity? Mine is directly under Assets, the folder structure looks like this:

    Code (csharp):
    1. Vectrosity/
    2. ├── Plugins
    3. │   ├── Editor
    4. │   │   ├── VectrosityEditor.dll
    5. │   │   └── VectrosityEditor.dll.meta
    6. │   ├── Editor.meta
    7. │   ├── Resources
    8. │   │   ├── DefaultLine3D.mat
    9. │   │   └── DefaultLine3D.mat.meta
    10. │   ├── Resources.meta
    11. │   ├── Vectrosity.dll
    12. │   └── Vectrosity.dll.meta
    13. └── Plugins.meta
     
  38. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    31
    Exactly the same place although Vectrosity no longer uses DLLs and has switched to a source only approach in the latest release (5.6.1 - October 2020 so not that new).
     
  39. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    31
    Yeah pretty sure that is the problem. I just did an experiment where I installed the three packages then manually moved the Vectrosity backend code into the main project (deleting its asmdf file) and then removed the package installed via git and that fixes the errors. The vectrosity sample scene kind of works (some things are broken as references are now invalid and I have no idea what used to be hooked in) but it does at least look like it compiles and runs (I can see the colourful Vectrosity grid) it looks like your package had a dependency on the DLL implementation in Vectrosity that is no longer valid since they stopped using DLLs.

    Edit: Hooked in VectrosityBackend scripts as the missing components so all the demo elements work now. This is a workaround for the time being and gets everything functional again but it would be great if this just worked out of the box with the non-DLL Vectrosity version.
     
    Last edited: Jan 7, 2022
  40. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    625
    Yes, that explains it. The problem is with how Unity compiles scripts into .NET assemblies. Packages live in a separate assembly and by default they only have access to the Unity standard library, but not your own scripts. For that you have to create your own assembly definition. Grid Framework has one (I created it specifically so that Grid Framework would work with packages), and when using the Vectrosity DLL no extra steps are needed. However, if you use the source version of Vectrosity, the Vectrosity code is indistinguishable from your own code for the compiler.

    There are two solutions: one is to ask the author of Vectrosity if he can add an assembly definition. I am not aware of any downsides to doing so, but that doesn't mean there aren't any. The other solution is to add an assembly definition of your own, which is what I have done. Inside Assets/Plugins/Vectrosity/Scripts create an assembly definition (name does not matter, but I called mine "Vectrosity") with the following contents (or if you prefer the GUI set the fields to match the screenshot):

    Code (csharp):
    1. {
    2.     "name": "Vectrosity",
    3.     "rootNamespace": "Vectrosity",
    4.     "references": [],
    5.     "includePlatforms": [],
    6.     "excludePlatforms": [],
    7.     "allowUnsafeCode": false,
    8.     "overrideReferences": false,
    9.     "precompiledReferences": [],
    10.     "autoReferenced": true,
    11.     "defineConstraints": [],
    12.     "versionDefines": [],
    13.     "noEngineReferences": false
    14. }
    Next you need to instruct the Grid Framework Vectrosity backend package to use that assembly. Unfortunately Unity won't let you edit Git packages through the GUI, so you will have to edit the assembly definitions by hand. There is one inside the Runtime folder and one inside the Samples folder; double-click each one in the Unity editor to open them in your text editor and adjust the list to include your Vectrosity assembly definition, e.g.:

    Code (csharp):
    1.     "references": [
    2.         "com.hiphish.grid-framework",
    3.         "com.hiphish.grid-framework.vectrosity.Runtime",
    4.         "Vectrosity"
    5.     ],
    Replace "Vectrosity" with whatever you have called your Vectrosity assembly definition.

    I'm afraid this is as close to "out of the box" as I can make it for now. I could add the "Vectrosity" reference blindly, Unity does not seem to have an issue with non-existing references (I was able to build and run without issues on Linux), then users would only have to drop in the Vectrosity assembly definition. What do you think, is that an acceptable compromise?
     

    Attached Files: