Giter Club home page Giter Club logo

dn2gamegrids's Introduction

Dn2GameGrid

Unreal Engine 4 plug-in for square and hex grids and simple A*(Star) pathfinding. An instance of a grid is managed by an Actor that holds an array of the cells (points/nodes) on the grid. There are helper functions in both C++ and Blueprints for you to manipulate the grid, it's cells and your gameplay actors. Made and tested in Unreal Engine 4.27.

Features

  • Async grid generation
  • Async A* pathfinding
  • Non iterative cell validation
  • World Location <-> Grid coordinates conversion
  • GameplayTag based filtering for cell retrieval

Not Implemented (Yet)

  • Hexagon version
  • Common helper cell selection operations (think trace and overlap but for cells, sorta)
  • WFC (Wave Function Collapse) base class
  • Map importing

Setup

  1. Install plugin to your project's plugin folder and enable it by going to Edit > Plugins. e.g: MyProject\Plugins\Dn2GameGrids
  2. Add a BoxGridActor to your level or create a blueprint with BoxGridActor as its parent class.
  3. In the details panel of your placed BoxGridActor or class defaults panel of your blueprint, under the Grid category, check bAutoGenerate, and set the extents or your grid.
  4. Alternately, you can skip step 3 and use the blueprint node Update Grid Async to build your base grid at runtime. Update Grid Async overwrites the current grid if there is one.
  5. Additionally Update Grid Async, on completion fires off Blueprint and C++ events with the resulting grid array, grid extents and cell size.

Terminology

  • Cell: A point or node on the grid with associated 2D coordinates (e.g 4,20). See Cell Info.

  • Cell Address or Address: the 2D coordinates (e.g 7,11) that represent a position on the grid.

  • Cell Info: FCellInfo Struct that holds the info for the cells on a grid. UpdateGridAsync() populates TArray<FCellInfo> GridArray with these. You can find FCellAdress, FGameplayTagContainer, etc held within.

  • Cell Tags: FGameplayTagContainer that holds the FGameTags that are associated with a Cell Info.

  • Grid Extents: The extents of the grid. A FIntPoint, X being how many cells wide and Y being how many cells 'tall'.

  • Neighbors: Any cells directly next to a given cell. e.g. GetCellNeighbors() returns cells next to a given cell.

  • Cell Size: The size of a cell when calculating its dimensions & location in world space in relation to the AGridActorBase that owns it.

Types

Name Members Description
FCellAddress int32 X in32 Y Coordinates for a cell, X and Y
FCellInfo FCellAddress Address FGameplayTagContainer CellTags Used for grid array. Holds info for each cell in the grid array
FAStarCellInfo float H float G float F FCellAddress Address FCellAddress CameFrom Used for the A-Star algo
FAStarSearchResults bool bFoundGoal TArray<FCellAddress> Path Struct holding the results of AStar search algorithm

AGridActorBase Members

Name Type Description
bAutoGenerate bool Show a grid preview in editor & generate on BeginPlay
CellSize float Size of cells
DefaultCellTags FGameplayTagContainer If bAutoGenerate, generate a grid on BeginPlay using these Tags
GridArray TArray<FCellInfo> Array holding our grid cells
GridMeshComp UStaticMeshComponent* Visual of the grid and trace collisions for world locations <-> grid address conversions
GridMat UMaterial* The material we'll make and instance of and use for visual debugging

AGridActorBase C++ Functions & Blueprint Nodes

Name CPP BP Description
UpdateGridAsync Yes Yes Create default grid for this grid actor. Populates TArray<FCellInfo> GridArray. On completion calls C++ event ABoxGridActor::OnUpdateGrid_Internal and blueprint event ABoxGridActor::OnUpdateGrid with the results of the grid creation.
GetPathToGoalAsync Yes Yes Create default grid for this grid actor. Populates TArray<FCellInfo> GridArray. On completion calls C++ event ABoxGridActor::OnUpdateGrid_Internal and blueprint event ABoxGridActor::OnUpdateGrid with the results of the grid creation
CreateEmptyGrid Yes Yes Create a grid array that you can do what you want with. Not Async. No sort of setups of anything. Just returns an array of FCellInfo
AStarSearchToGoal Yes Yes Not Async. Try to find a path to the goal given addresses and optional filters, using an AStar pathfinding algorithm
GetCellLocationFromAddress Yes Yes Given the address of a cell (e.g 12,24) return the cell's world location. Uses the Actor's GridArray
GetCellAddressFromLocation Yes Yes Given a world location (e.g FVector(123,456,10)) return a cell address IF the address is valid. Return value of FCellAddress(-1,-1) means there is no cell associated with given location. Uses the Actor's GridArray
GetIndexFromAddress Yes Yes Given the address of a cell, return the Index for that cell's FCellInfo in AGridActorBase::GridArray. Avoids iterating arrays by just calculation its index
DoesCellExist Yes Yes Returns true if the given address is valid and the FCellInfo in the assumed index of AGridActorBase::GridArray matches
GetCellInfoByAddress Yes Yes Given and address returns the associated FCellInfo from AGridActorBase::GridArray. Make sure the returned FCellInfo::Address is valid. i.e. not FCellAddress(-1,-1)
GetCellNeighbors Yes Yes Given an address, an array of neighbouring cells are returned. Optionally filtered using GameplayTags. ToDo: maybe return addresses instead of cell infos
GetGridExtents Yes Yes Returns the extents of the grid.

dn2gamegrids's People

Contributors

dn2 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.