Monday, December 31, 2018

Refactoring to Transfer Functionality Between two MonoBehaviour Implementations

This was a lot of fun. I had one MonoBehaviour class that was hosting behavior which rightly belonged to another. I transferred the method containing the behavior, wrote down the parameters as writes to public fields, and inlined the bit that did the writes to the public fields, leaving the functionality on the other MonoBehaviour class. Then, I configured all the properties on my prefab in the editor.

Once I did that (correctly, it took me two tries), I was able to delete the fields from the old MonoBehaviour class, signifying that I had completely and correctly transferred the behavior.

It was fun.