Pages

Monday 2 February 2015

Week 18: Through Sweat and Tears - And Blueprints! (Post-Mortem)

Unreal Scripting

Where do I begin? - I finished off last week by writing about my torch and the problems I encountered with it, however this was just the beginning of all the scripting I had to do, in order to get this level to work. I wouldn't consider myself a scripter/programmer, however I did have previous scripting experience as well as a pretty strong logical mind and that definitely helped a lot in this project.

The scripting system in unreal engine 4 is known as blueprints. They are easy to understand for most people (even those who have never done any programming), but when it comes to complex scripting it can be quite hard and I learned that the hard way. While most of the things I wanted to script into the level were quite simple, they turned out to be a bit harder for some things. For example:

I wanted to make text appear on the HUD. One bit of text which shows the controls to the player, that can be toggled by holding a button and several other bits of text that appear and fade away when you pick up items, etc. While that might sound quite hard I didn't expect to produce something as complex as this!:
HUD Blueprint
I can already hear some of you say:"But Hey! HUDs are never really easy to create!" - and that's true! - However, there was even simpler things that were a lot more complicated than they had to be. Like Global Variables.

Why can't I just create a variable in the level blueprint (which btw. has access to any component within the level) and then be able to change it within every other blueprint? There is of course a way to do this, however it's a bit more complex. It involves either in you having to link 2 blueprints that you want to interact between together or you have to use what is known as casting. Now, for those of us that never heard of casting: It basically means that temporarily you switch over to another blueprint and do something AS that blueprint. For example if I want to have a global variable (or at least something similar to that) then I can create a public variable in blueprint A and then in blueprint B cast to blueprint A and set that variable to whatever I want to set it to.

If it was that simple, it wouldn't have been a problem though. It is actually even more complex. On top of the casting, you also have to specify which EXACT blueprint instance you are casting, too. This means the blueprint needs to be in the scene so you can select to cast to that particular instance, which then again is not too bad, until you get to the HUD or player controller. Which are both blueprints that are NOT in the scene, but rather get created once you play the game. In that instance, however, UE4 has got a simple node to help you out for that such as 'Get Player Controller' and 'Get HUD', but WHY is this so complex? All I wanted to do is set a simple variable to true and let ALL blueprints know about it!

Anyway, enough ranting. Another feature that I implemented which took quite a bit of scripting was the flashlight. I wanted it to move together with the camera. First I had to change the pivot point to be very similar to that of the camera itself and then it took a bit of scripting to find and set the position of the camera and the flashlight. I also created a socket at the front of the flashlight for the light itself to be in, so that the light would move with the flashlight. Here is a quick overview of the blueprint for the flashlight rotation:
Set Flashlight Rotation
Finally another scripting challenge was the end part of the level. We planned for our level to end with an elevator, so I had to script in the button to open the elevator door, which would only work if you had previously turned on the generator. It would have to open the door and upon the player entering the elevator I wanted a message to appear that told the player to press E to end the level. I would then want to switch the player to a camera and slowly fade out the level, while playing music and having the elevator rumble to create the illusion of it moving. After quite a lot of time scripting and testing I managed to produce this:
Elevator Ending Blueprint

The Final Result

I did manage to get there in the end and managed to complete the level; And I have learned A LOT about Unreal in the process. I can now safely say that I am pretty confident in scripting within UE4, which is great! Unfortunately, I haven't been able to do much else within this project. I was mainly focussed on getting everything to work and creating the materials in engine. I also got sounds to help set the atmosphere. I did model a very few objects, however my main part in this project was unreal, therefore I can't show off much. I am, however, able to show a video of our level. We had problems with the framerate and ultimately only got it up to 40-50 FPS, which meant that in the recording process it was running quite slowly, so I was only able to record it at a resolution slightly lower than 720p. I scaled it up a bit and here is the final result: 

No comments:

Post a Comment