Skip to content

Instantly share code, notes, and snippets.

@cobbpg
cobbpg / Unity-hotswapping-notes.md
Last active October 10, 2024 05:55
Unity hotswapping notes

Unity hotswapping notes

Unity has built-in support for hotswapping, which is a huge productivity booster. This feature works not only with graphics assets like bitmaps and meshes, but also with code: if you edit the source and save it, the editor will save the state of the running game, compile and load the new code, then load the saved state and continue where it left off. Unfortunately, this feature is very easy to break, and most available 3rd party plugins have little regard for it.

It looks like there’s a lot of confusion about hotswapping in Unity, and many developers are not even aware of its existence – which is no wonder if their only experience is seeing lots of errors on the console when they forget to stop the game before recompiling... This document is an attempt to clear up some of this confusion.

Nota bene, I’m not a Unity developer, so everything below is based on blog posts and experimentation. Corrections are most welcome!

The basic flow of hotswapping

@cobbpg
cobbpg / gist:37473f33e8bcd3ec14bc
Created July 10, 2015 21:18
LambdaCube logo in LambdaCube
clear = FrameBuffer $ (DepthImage @1 1000, ColorImage @1 navy) -- ...
triangleRasterCtx = TriangleCtx CullNone PolygonFill NoOffset LastVertex
colorFragmentCtx = AccumulationContext (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
rasterizeWith = Rasterize
triangles = triangleRasterCtx
cubeVertexStream = Fetch "stream4" Triangles (Attribute "position4" :: Vec 4 Float)
{-# LANGUAGE Arrows #-}
import Control.Arrow
import Control.Category
import Prelude hiding (id, (.))
-- Only for testing
import Text.Printf
newtype SF a b = SF (Float -> a -> (SF a b, b))