yea thats totally not the impression i was under, you made no mention of turn based. ok well now theres a clear picture of what your looking to do so that helps.
the first thing is to decide how you want to create your levels. you have two options here you can procedurally create the floor using loops or you can place all actors yourself which will probably be best for walls and such.
the next thing to work on is the movement. if your player can only move one step per turn then you could easily setup a system like above which uses a line trace to ensure that the player isnt facing a wall and can get to the next space. you may also want to have a check to see if the space is occupied by another character. then the last task is to move the player character which can be done with a simple move to.
now the way ive done this in the past was to create a actor that represents each grid space but this could also be done in other ways. what i used the actors for was a reference for location and to store information like if the space is occupied. ive placed the flooring pieces in the actors but it may be more performant to just use a collision volume in the actor. anyway create a actor bp that contains something that will represent one square (mesh or collision volume). then create a variable of type bool and name it “IsOccupied?”, this will represent if there is another character/enemy on that space. now you will need to place many of these actors in your level to create the grid. I personally use a spawner actor to do this for me so it can be done with one click and so its done accurately. maybe ill cover making the spawner at the end. in the next section i will be referring to the actors that represent the grid as tiles to keep things simple.
now on to the player characters movement. in the player character we first want to get a list of all the tiles in the level and save it for later use, so on begin play we get all actors of class then promote the output to a variable by right clicking its output pin (char1 picture). now skip the rest of the begin play script for now we will get back to it later. move on to picture two (char2).
in picture two you will see how we do the basic forward and back movement. we start by getting the input events for movement. next create a variable which represents the distance you want the player to move, i used 100uu for this example as thats how big my tiles are. if this variable is positive then we will be moving forward, if negative we will move backwards. we next need to do a line trace to see if we are facing a wall.
the link is a text doc that contains all the explanation. hopefully this helped you out a bit.
turn based games and grid movement is a bit advanced so it may be a bit difficult. im also not a expert so it may not be perfect but it does work and what i provided should be enough to get you started toward your goal, modify as needed.
Hi blaze, I wrote that blog post about grid generation a few years ago. I stopped working on that project a long time ago, but an improved version of that grid generator is still being used in my other projects. So if you want it, I can share the blueprints with you.
Meanwhile, if you’re interested in using a custom pathing system for your AI, I’d definitely recommend taking a look at Monokkel’s Advanced Turn Based Tile Toolkit in the marketplace. He has created a solid pathfinding system that has received a lot of improvements over the past couple of years. So unless you want to learn and create your own pathfinding system from scratch, you might find it really useful.
Thanks so much for the help, I tested it and it works although I got a bit stuck with as the actor isn’t moving even though I got nav mesh bounds volume there, I’m guessing it’s because I haven’t spawned the grid but I’ll get on that now, thanks again.
o yea i never showed the spawner huh. the link below shows how to make a script to spawn a grid of tiles (starts at about 5 min in). the one i made actually used the spawn actor and was run in the editor instead of runtime by checking the box for run in editor on the event node.
You can just add in the BP_GridGenerator blueprints into your level and then will generate grids. It can create grids only on a plane. Use GridCountX and GridCountY variables to control the number of grid cells along local X and Y directions.
And information about the grid can be accessed through GridData array in BP_GridManager.
Sorry for bothering you and digging up the topic but since I had exams I didn’t have time to try this until now, by following the tutorial I was able to generate a static mesh but I wasn’t able to figure out how to get the construction script to spawn actor “Tile” actor that is refrenced in the character movement, would it be possible for you to briefly explain how you did that?
the simple answer is i didnt. i used a custom event that can be called in the editor. when i did it i was making a predefined level, so i had everything setup and existing in the level before the play button is ever pressed. what my spawner did was to create the tile actors and place them. after that i was free to delete the spawner actor.
to make an event that you can run in the level editor window all you need to do is create a custom event, select it, then in the details panel check the box for call in editor. then place the actor in the level (this actor will just be there to spawn the others). finally if you select the spawner actor and go to the details panel you will see a button for your event in the same place you would usually see public variables, click the button to execute the script.
you dont “need” the spawner at all, i used a spawner actor to place the tiles instead of having them created at runtime or having to place them by hand. imagine you wanted to create a grid of tiles, it would be time consuming to place each one by hand right, so instead i just made a script i could run in the editor which places the tiles in their grid positions automatically. so the spawner is just something to save time and make things easier. you could just place the tiles yourself or come up with your own solution to placing them.
I do intend to use the spawner so it makes it easier than placing it indiviually.
This is what I have so far, I couldn’t figure out how to get the spawner to refrence the “tile” actor used before and if I’m missing something in the level blueprint.
with what your attempting to do you cant use the construction script. you are trying to spawn the tiles that you need, and the spawn node doesnt exist in the construction script.
ok heres what i did to make the spawner. create a custom event (BuildGrid), with the event selected go to the details panel and check the box call in editor. then create the spawning script off that event by using two for loops and a spawn actor of class node. in the below example i used a square grid with a tile size of 100. once you have the script completed place your spawner actor in the level. now select the spawner actor in the level, then in the details panel look for the default section, now find the button which has the same name as your custom event in my case build grid, click the button. once you click the button the script will be run and your tiles will be spawned.
also note i included a section in my script which destroys any tiles currently in the level so if i want to change the grid size and rerun the script i wont have extra tiles.
the error is from a script trying to read the value of current tile but it hasnt been set or doesnt exist yet. i would guess that your character doesnt have a current tile to begin with so the value isnt set. you have two options if this is the case you could add in a IsValid? node prior to the set, or you could set the initial value of current tile variable by making it public or having a script to set it on begin play.
i dont understand what your trying to say. you already have a variable for current tile its value just is not set. basically its trying to set a variable (isOccupied) in a actor (currentTile) but doesnt know which actor to target since the current tile variable is not set (has no value).