Legacy Code Strikes Again...
By: Matthew Steinhardt
As we come down to the wire to get everything implemented, the mouseover UI for the tower information was still being developed. After the implementation was pushed to the main project, it was apparent there was a problem. Oddly, enough the overlay system didn't seem to work when the player mouses over towers that were loaded in from a save state. Upon further investigation, it became apparent that a mysterious "TowerData" structure was not being saved/populated properly on towers loaded from a save state.
This was rather perplexing as this TowerData structure wasn't used in any other tower system. I tracked down used references in Unreal Engine and found out that it was a legacy system put in during the first weeks of development while trying to figure out a way to pass some simple data between the Tower Bar UI and the icons. Unfortunately, this system was largely abandoned in place of our better Data Asset implementation.
It turned out that the TowerData object was a wrapper class around the TowerInfo data table which kept a very basic list of our towers, names, icon, etc. This was meant to just be used in the "TowerSelected" event to trigger creating a tower for placement. Somewhere along the way, this TowerData class was added to the base Tower class as well and was then used in the overlay system instead of our new Data Asset system.
So the question became: Do we completely rewrite the overlay system to utilize the data asset system, or do we try and support the legacy code and bandage it up? Due to the time constraints, I opted to go with the latter. It proved to be slightly more time consuming than anticipated. I ended up having to add the data structure to the save system and save it for every tower. Then during load, I applied that data to the wrapper class.
![]() |
The struct is duplicated and stored for each tower unfortunately... |
The moral of the story here is: always expect people to find old code and use it in ways you don't anticipate. Some extra time upfront removing legacy systems would have prevented this. But such is the way of things when you're constantly on a tight crunch schedule.
Comments
Post a Comment