Tuesday, July 10, 2018

Gamepad menus and more!

I decided I wanted to give full gamepad support for the playable version of the project, which means menus must be navigatable using the gamepad. UE4 does not natively support gamepad navigation through UMG (only point-and-click with a mouse), so the programming must be done manually. I watched this video (several times) to learn how to do this: 



Figure 1: the programming that is called when the game starts. It displays the Main Menu, and defines actions for gamepad Up and Down buttons (in red), as well as the A button (Gamepad Face Button Bottom) to select. The nav types within the two blue functions are defined by an enumeration (not shown) that contains of two variables: main_up and main_down. 


Figure 1 - Main Menu Level Blueprint

Figure 2: the designer tab for the menu widget, which I created in December. Not much to see here other than that there is an animation timeline keyed to all of the elements:

Figure 2 - Main Menu designer tab

Figure 3: the blueprint for the menu widget. There is a lot going on! At the top, starting with EventConstruct, the fade-in animation is called, and Debussy's "La cathédrale engloutie" (Sunken Cathedral) is played. Then the button appearance is set, which is referenced by functions on other tabs. On the far left, there are red OnClicked and custom Event functions. These each get their own instructions, which flow from left to right. For example, when OnClicked_Main00Explore is called, this displays the loading screen, waits a few seconds, opens the UHS_1914_building level, then removes the Main menu widget. The OnClicked events are created automatically from the Designer tab; the custom events are created by me. At the top of the blueprint, within the gray box, is the array which sets the appearance of the buttons, and at the bottom within the gray box is the index that defines each of the buttons as an integer so that the buttons change with OnMouseHover as well (usually, the Mouse Hover colors are defined on the designer tab, but then it ignores the "Update Appearance" function, so I have them both updated here). In theory, I could have cleaned up this blueprint by making each button action as a separate function, which would each be listed on separate tabs, but chose not to. 

Figure 3 - Main Menu Widget blueprint
Figure 4: the function that is actually referenced on the level blueprint. It receives the gamepad navigation requests (from the level blueprint, figure 1) -- either up or down based on the nav type -- and calls additional functions based on this request. 


Figure 4 - "Receive Navigation Request" function
Figure 5: the Receive Main Down function. If the player moves the joystick down or presses down on the d-pad, the Main Navigation Index is increased by +1. There are five buttons;  the top button is 00, the second 01, etc. If the navigation index integer is less than 4, it adds +1. If the Navigation index integer is greater than 4, the index is returned to 0. That way, if the player has the bottom button selected (button 05), the selection loops back to the top (button 00). There is also a subtle "tick" sound played when the index is changed. 

Figure 5 - "Receive Main Down" function
Figure 6: the function for Receive Main Up. It is the same as the down function, but instead of adding 1, subtracts 1. If the integer is greater than 0, then -1 (it will not be any larger than 4, according to the Receive Main Down function, figure 5). If the integer is less than 0, it is changed to 4. 

Figure 6 - "Receive Main Up" function
Figure 7: the function that changes the appearance of the buttons. There is a ForEachLoop that creates an array referencing the navigation index (the integer modified in figures 5 and 6) , and sets the background of the button based on that integer (clear if false, subtle gray if true). 

Figure 7 - "Update Main Nav Appearance" function
Figure 8: the function called when the gamepad A key is pressed (as defined on the level blueprint at the beginning, figure 1). This uses the navigation index integer to choose which of the custom events are called (in red on the left of the Main Menu blueprint, figure 3).

Figure 8 - "Receive Gamepad Select" function
All of these blueprints together allow the player to interact with the main menu with either a mouse or a gamepad. Whew!

After spending eight hours adding this to the Main Menu, it was easy to add gamepad functionality to the pause menu within the game itself. The differences within the level are that I had to set the game as paused so that the Up/Down navigations did not make the player pawn move in the background. Otherwise, the gamepad could select invisible Pause menu items as the player navigated the map, since the functions for the pause menu navigation are available thoughout play. Also, the Pause Menu is actually created from a separate level that streams temporarily over the UHS_1914_building level. This sets the main game as paused, but also means the gamepad actions defining the pause menu navigation have to be set as "execute when paused", otherwise nothing happens. With Play-in-Editor (PIE), I was able to navigate from the Main Menu, to the building level, back to the main menu, and to the Gallery level -- all with a gamepad. Success! Then I clicked Save, and closed the editor. Enter: roadblock!

Here is where the roadblock appeared: I had great success with the Main Menu's gamepad functionality, but could not get the pause menu to work after saving and re-opening the level. I got the same error I received in March from my bug report: after reloading, the variables from the designer tab disappeared from the graph side of the UMG blueprint. This not only threw a compile error to the blueprint itself, but caused the project not to be able to be packaged (export-all to a stand-alone application). In addition, not only did I have the variable for the animation disappear (the error from march), but the variables that referenced the buttons also disappeared. In a few cases, trying to fix the missing variables crashed the editor. No good!

The a-ha moment came late yesterday afternoon. The question: why was the Main Menu working, but the Pause menu not working? The difference between the two situations is from where the CreateWidget is called. I had been calling the Pause menu from the FirstPersonPlayerBP (the blueprint that defines the player actions), since that is where I have successfully called the footstep sounds and the mini-map. However, the FirstPersonPlayerBP blueprint somehow negates the variables created within UMG blueprints. The Main Menu works fine because it is called not from the FirstPersonPlayerBP, but from a level blueprint for the empty Main Menu level. As soon as I switched the Pause menu to call from the level blueprint instead of the FirstPersonPlayerBP, it worked! Nearly the entire project can now be controlled both by a mouse/keyboard, and from a gamepad. 

To celebrate this success, I modeled a vault ceiling to add to the porch on the Gallery level: 



Edit July 11: with the addition of the options menu, the entire project now has full gamepad support!

Monday, July 2, 2018

Auditorium cove corner and brick quoins

The auditorium has a large plaster cove where the walls meet the ceiling. In the outermost corners, there is an overlapping corner that is much more complicated than the others. Two of these complex corners were covered by the recent renovation, but the corners in the balcony still exist just inside the doorway:


I have tried several times to model this in Blender, but finally figured it out using 12 different Boolean modifiers for the 6 corners. The orange squares are where I made the slices (one seems to be hidden in this screenshot):




Also, after a lot of tedious UV mapping, I created the brick quoins which are on all the exterior convex corners of the building:




The texture looks a bit repetitious when viewed close-up, but this is not a problem when viewed from afar. 

Sunday, July 1, 2018

Build problems & gym entrance

The blueprints bug that plagued me in late March has made a return (see my March 2018 entry for details). Basically, the problem has caused my project to refuse to build a package (as in, create a version that can be run independent of the Unreal editor). I have tried numerous options, with the most drastic being copying all of the assets to a fresh project, and deleting all of the menus. I emailed Epic support again about the issue, and am eager to find out what they suggest. 

All of these options have been time consuming (copying all assets, building a new project, uploading the entire project to Google Drive to send to Epic tech support), and the UE4 engine cannot be used while the tasks are processing. While I was waiting, I started modeling the gym entrance:





Tuesday, June 26, 2018

World space materials

World space, or world aligned materials use an absolute position in the map to determine how to display the texture, instead of relying on the UV wrap of each mesh. I have experimented a bit with world space aligned materials before, but finally got them to work. The wood floor I have been using from the PolyPixel Freebie set is already world aligned, so I just transferred those material nodes to my custom 6x6 hall tile. However, I learned how to do it myself, and I changed the interior brick materials to world aligned materials so it is easier to place the tile coves throughout the ground floor of my school level. I learned how to create these using this excellent video: 



I ended up using a slightly different method when it came down to connecting nodes in the materials editor, but he explains it very well. 

My versions are below. With the world aligned materials, the normals don't work correctly if the texture is facing the wrong way, so I had to make separate x-facing and y-facing versions. There is probably a way to do this within a single material, or through a material instance, but that is beyond my abilities for now. In these screenshots, the tile coves are two separate meshes: one for the long sections, and another for the corners. They line up perfectly because they have the same axis. The textures always line up because they use the same world aligned material as the adjacent wall. Also, I am able to use the same mesh for all of the long sections because the world aligned material automatically scales the texture properly. The wood wainscot sections all have to be separately scaled in Blender and imported because the wood material is not world aligned. These world aligned brick materials have saved be numerous hours in scaling and importing -- I just line up the axis of each tile cove, and they're done!





Saturday, June 16, 2018

Hallway details video

As mentioned yesterday, I created a video showing the steps I use to create the hallway trim elements in the UHS: 1914 project. 


I apologize for the audio quality. I used my headset mic for the first time in years; in the future, I will use a real mic. 

Friday, June 15, 2018

Hallway details and props

I have been busy finishing details on hallway wainscot and marble bases. This is a very tedious task, and takes a while. I may make a video of all the steps required. This is the finished product, though:



To break the tedium of doing the trim work, I created some props in Blender. The wire on the phone is my first successful use of curves in Blender. Curves make it tons easier! (video tutorial at https://youtu.be/jmzXqjEdF0E




More items for the main office, including file cabinets and the 1869 map of Urbana: 



Period appropriate US coins (after an afternoon of research into currency available in 1914):


A desk fan based on a 1909 model (also using curves for the guard on the front). The animation is triggered when the player enters the room:


I decided I did not like how the "murals" looked in the Gallery, so I replaced them with embossed Tudor-inspired wallpaper, and updated the greeting panel to match:




Thursday, June 7, 2018

Typewriting classroom

The reference photos from the 1926 Rosemary include a photo of the Typewriting classroom:



I had already created the room long ago from the blueprints, but the props were still to be created. I found a model of a Typewriter online:  



Created my own typewriting desk based on the reference from the 1926 Rosemary:



And finally found the cover of a period typewriting textbook:



And all the pieces together in UE4:





The phrase on the chalkboard is from one of the later chapters of Rational Typewriting method.