Unity hot-reload extension for LeoECS Lite and LeoECS Classic.
Hot-reload (officialy Domain Reloading) is the feature of Unity Editor that applies script changes without exiting Play Mode. It works by default (at least in 2021 and earlier), but can be switched off in Editor Settings.
Both LeoECS Lite & Classic are supposed to work with hot-reload disabled, as their state is not serializable and truncates after hot-reload. This library is about to serialize all entities and components at right moment.
Notice: Though, hot-reload may increase developer productivity, it also it requires practice and attention for good flight, because easily leads game session into incorrect state
- Based on built-in Unity serialization
- Entity cross-references support
In order to support cross-references, library deeply transforms components using reflection before leaving it to Unity's serializer. But transformer mimics Unity's serialization rules, so you shouldn't care.
Implementation is simple and allocation intensive. Need to test if that's ok at least on common dataset sizes.
Add following line to Packages/manifest.json's dependencies section:
"com.nplekhanov.csx.leohot": "https://github.com/kkolyan/leohot.git#classic",
Add following line to Packages/manifest.json's dependencies section:
"com.nplekhanov.csx.leohot": "https://github.com/kkolyan/leohot.git",
Note that usual ECS initialization (systems and worlds definitions) moved from Start to OnEnable - that's mandatory.
public class MyMonoBehavior: MonoBehaviour
{
[SerializeField] private SerializableEcsUniverse packedUniverse;
private EcsSystems _ecsSystems;
private void OnEnable()
{
// usual ECS systems and worlds initialization
_ecsSystems = new EcsSystems(...);
...
_ecsSystems.Init();
#if UNITY_EDITOR
if (packedUniverse == null)
{
packedUniverse = new SerializableEcsUniverse();
}
// restore components and entities that were serialized during hot-reload
// that's safe to call even first time when there nothing to restore
packedUniverse.UnpackState(_ecsSystems);
#endif
}
private void Update()
{
// usual update actions
_ecsSystems.Run();
}
private void OnDisable()
{
#if UNITY_EDITOR
// dump components and entities to the hot-reload friendly format
packedUniverse.PackState(_ecsSystems);
#endif
}
}