Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

My next goal was to create and comfortably texture of house

A topic by will.anstey created Dec 01, 2022 Views: 86
Viewing posts 1 to 1
Developer (5 edits)

The process of creating an in-game interactable building felt like the first development process in that I could do the majority without needing to use a tutorial, therefore I did less work before beginning development and later felt this come back to bite me as I struggled to properly texture the building.

Starting out I looked through the unity asset store to find some house assets that I could convert over to unreal, after finding a couple of asset packs, for example, I realised that most didn't have the inside of the houses included and were instead just boxes. After realising this wouldn't give me wanted I attempted to create a house of out cubes in unreal and texture it. I was able to create a house of simple cubes and texture it with textures found online but this create stretched textures and meant that in the end I was dissatisfied with the product and decided to restart.

For the final time, I decided to use Unreal assets as I have a module house asset pack already and it would allow me to build up houses with an inside space for furniture and therefore be the perfect asset to implement. Implementation was easy enough, downloading the assets into the scene and then dragging the actors into the worldview, and setting their textures properly were all problems i had overcome before and did not pose much of a challenge.

However, difficulty arose when trying to plan my methods for changing textures in real-time. I hadn't considered that the show itself would need to be a blueprint actor in order to change the textures affecting it.

In order to flip between two textures for the house I knew from previous work I'd have to use a dynamic material but didn't understand how I could make a system that flips between two different materials at the click of a trigger.

Unreal API writing Team. 2021. Set Material. https://docs.unrealengine.com/4.27/en-US/BlueprintAPI/Rendering/Material/SetMate...

The setMaterial node was the first I came across when attempting to set the material of the house to one of the others provided in the asset, the API was very vague and was unhelpful during development. Whilst when attempting to use a sequence to flick between the two different desired materials I found that after clicking the trigger the material would not be set to the next and instead stay on the material set to the static mesh when I added it to the blueprint.  

I created the code seen above to switch between each material when the player pressed the trigger but instead nothing happened.

During research into how to get the controller input to actually affect the sequence and change the material I had a source control error where I lost a large amount of my work and started from scratch on the material-changing feature

After this loss of work, I decided to do the same as before up to the point of programming where I would just follow a tutorial and learn from that.

Tutorial Used: Dean Ashford. (2018, July 8). UE4 - tutorial - Change Textures at Run Time. [Video]. Youtube.   https://www.youtube.com/watch?v=FY5P8-9MYfg&t=313s&ab_channel=DeanAshford

To start I had to initialise the base material as a dynamic material instance to allow the texture to change, to do this I added a Create Dynamic Material Instance and a Set material node, these two nodes paired together initialise the actors material as a dynamic material that can be changed in real-time. Then using an Enable Input node and feeding in the player's controller with the Get Player Controller node I am finally able to have the player trigger the switching of the textures.

Lastly, all that is needed now is to actually allow the player to trigger the switch, to do this I used the inputAction triggerLeft event which is an inbuilt event from unreal, then feed the pressed output into a flip flop node. Using a flip-flop will allow me to just flick between the textures with each press, eliminating the need to reset the material. Finally using the Set texture Parameter Value I can change the base color parameter of the actor. At first, this solution did not work for me but my new knowledge showed itself whilst I was debugging as I deconstructed the possible issues in my head and quickly realised that I must not be promoted the texture in the material to a parameter, which turned out to be correct.