This is so entry level it’s embarrassing, but not being able to get a lego-block scripting system in another engine to do this is what originally pushed me over to UE4. I wanted to create an array of floor tiles to move a guy between, and when I asked the program if I could get some information out of the array it smiled and asked “Why would you want to do that?”
Now arrays were the math that I reached in school that finally made me commit to being an artist full time so trying to tackle them was an added aspect to this challenge. It took me about three weeks to get back to where I was in that other program. UE4 is simultaneously both more intuitive to use and more obtuse to interpret. This likely has a lot to do with me simply not understanding how it’s trying to talk to me, and just learning “where is the bathroom” has taken a lot of nights and frustrated google searches. So it’s a bit steeper in it’s opening learning curve, but once that barrier is pierced holy cow does it open up.
So I figured out to get the player shunted into a camera, then tossed in a some placeholder art. I spent a bunch of time looking at how inputs were handled and realized that my player movement has more in common with an elevator than a standard hold-a-direction-apply-velocity player character. With that break through I was finally able to get him moving on an arbitrary number using the following:
So he’s moving! But **** if it wasn’t a bitter taste because it was just any old number right? There was no accuracy to it and if I had stretched my game space out, or made any alterations to the size of the objects in question, the character would have ended up off of the center of the tiles. I needed something that I KNEW was putting him on the floor tiles exactly, and I needed those tiles to be able to communicate to me and with the wider game. I knew I needed to get back to that notion of the array but even getting this far was like pulling teeth. The breaking point was when I noticed the “Context Sensitive” check box in the node search box! Suddenly I have access to all the stuff that UE4 thought I didn’t actually want because I was prototyping everything in the Level Blueprint, even stuff that will eventually shift over to class objects. I had access!
So I find the MakeArray node, get my actors plugged in, and cant seem to find anything that will take it’s weird box pin. I eventually spot a GET node in a screen shot that seems to bridge the gap between the array pin type and the standard round pin. I do a bit of checking and learn that theres a bunch of different ways to get information out of an array using one of those styles of nodes but GET seems to be the best for the job. I make some adjustments to the variable names and make sure my array gets built during the initial game start. This is where things get tricky. I have my player’s CurrentTile position number, so with a little trepidation I plug that directly into the lower left pin for the SetArray node. Seeing as I have the Set CurrentTile variable exec’ing the TileArray I worried a bit that this would be too self referential, but I reasoned that I’m going to want them to be the same number, at least for the moment.
With that assembled there was no way (that I know of right now) to be sure it would work without actually hooking a player’s movement keys to it and seeing what would happen. So building off my old arbitrary movement script I get something that says “Ok I pressed the Right Button! Hey Player Character, is your Current Tile less than six? I don’t want you running through a wall cuz that’s stupid”
“Umm” The Player Character looks at a number written on his hand, “No it’s ok! I’m on a tile less than six!”
“Good, I want you to move to whatever your Current Tile happens to be, plus one. Here’s a list of tiles. Do you see one that matches your number?”
“Yeah here it is,” Player Character checks between the two, “So that number plus one is…” He looks at the next tile in line, “It’s that one.”
Player Character starts moving to the new tile.
“Ok while you’re doing that I want you to make sure you stay at your same height”
“What?”
“Yeah I know, that’s a silly thing, but just make sure you don’t drill into the ground to try and get to that next tile. I’ll fix that when I make you a Class Blueprint of your own, probably.” I scratch my head, “I’ve gotta lock you to the x axis somehow…”
Player Character shrugs, “Ok whatever man.”
“Oh and one last thing! When you get to the new tile, I want you to write it’s number down so you don’t forget. I’ll probably be asking you to move again soon.”
“Got it!” The Player Character says as he reaches the tile. Before he stops completely he pulls his sharpie out and jots down a new number on his palm.
And all of that looks just like THIS:
Silly narratives to describe scripting aside this feels like a serious step forward with the engine. I had an idea, could think of roughly how it should be done, built it, and it WORKED. I’m so incredibly thrilled with the results I’ve had with UE4 so far and I really haven’t even gotten my feet wet. Also I have no doubt that what I’ve put together is cludgy in some terrible ways. If anyone wants to point out a better way of hooking things up I would love to learn from you. For example I can already tell that branch I have in my game start is completely superfluous. Gonna get that updated in a few minutes…
Next up is getting him to translate between two spaces and actually walk there instead of teleporting instantaneously.
This is exciting, I am excited!