Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17625

Unity Pattern: Stateless Scenes

$
0
0

Unity does not provide much direction on how to transfer game state between scenes. Some community suggestions are singletons, static variables or DontDestroyOnLoad. But these have other effects that you might not want. Here, I will share a pattern inspired by functional programming I call Stateless Scenes. This pattern, inspired by asynchronous APIs, leads to a much cleaner design.

We consider a scene to be: a long running operation that, given its inputs, eventually produces an outcome. We can rephrase that as: a function that accepts a callback (a.k.a. Action) in its argument list:

To actually implement this …


Viewing all articles
Browse latest Browse all 17625

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>