Skip to content

kkolyan/leohot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

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

Features

  • Based on built-in Unity serialization
  • Entity cross-references support

Implementation notes

Serialization

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.

Performance

Implementation is simple and allocation intensive. Need to test if that's ok at least on common dataset sizes.

Installation

LeoECS Classic

Add following line to Packages/manifest.json's dependencies section:

"com.nplekhanov.csx.leohot": "https://github.com/kkolyan/leohot.git#classic",

LeoECS Lite

Add following line to Packages/manifest.json's dependencies section:

"com.nplekhanov.csx.leohot": "https://github.com/kkolyan/leohot.git",

How to use

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
    }
}

Projects powered by

LeoECS Classic

LeoECS Lite

About

No description, website, or topics provided.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages