Today's post is to briefly explain how I implemented the dynamic weather/season changes in Garden Wars, using Unreal Engine 4 (see the last pic for the end result).
To keep things feeling fresh and different during play, the environment will change every couple of minutes. There are four "seasons": Summer, Autumn, Winter and... "Rainy". To achieve this, first of all, the materials used on the environment needed to be set up with colors that I could change to make them look like they belong in the season:
This needed to be done for every material on screen (luckily the environments in the game are very simple).
Then, I needed to set up the environment objects so they could be changed during play. To do this, I made a special subclass of StaticMeshActor that would create itself a dynamic material instance at startup, and it would also store information about what materials/colors to use for each season:
This custom actor has an array of four materials - one for each season. Also, to make sure I didn't have to specify those materials on every single mesh placed in the environment, I also made several subclasses of my custom actor - one for each type of mesh e.g. a FencePost subclass, a TreeTrunk subclass, etc. I could build the environment with normal static meshes, then all I had to do was select all of each type, and replace them with my custom actor via the right-click menu.
Next, I made a Timeline node in the Game State class. When this is triggered, for every season-changing actor in the level, it gets the colors for the current season and the new season (by looking up the array of materials I mentioned before), and smoothly interpolates between those colors over a few seconds:
Then, for testing and tweaking purposes, I made a one console command to trigger the season change, and another command to force-update all of the materials for the current season (allowing me to tweak colors of everything at once in-game). After that I went in-game and tweaked the materials for every season until it looked right:
Lastly, I made some particle systems and ambient sounds to compliment the color changes - snowflakes, leaves blowing in the wind, rain, etc:
Thats it! Here's a timelapse of it during gameplay:
There is probably more that could be added (like snow accumulating on things, a night and day cycle maybe), but due to time and mobile performance limitations (and the K.I.S.S. principle) I have kept it fairly simple.
There is quite a lot more complexity to the whole system than what I've described above, but hopefully that brief explanation is interesting enough. If you have any questions about specific things feel free to ask!
Don't forget to subscribe or follow in Twitter/Facebook/Reddit for more articles (links are at the top of this page)!