How to transfer the serialized data from components? - C++ Hot Reload integration

Long Story Short
Knowing that Ly has a customized reflection, a way to serialize data from components from C++, I’m wondering if it’s possible transfer data from an old version of the component to a new version, taking into consideration that the component might have changes in the variables, for instance a variable was deleted or added.

Additional question:
What happens if another objects is reading constantly (or not) public values of another components? Is there a standard way in Ly components to reference public values? or the official approach it’s always to “pull that data in every frame”?

More Info
After C++ Hot Reload extracts the new modified class and build the new version and call the constructor, the library has its own automatic serialization to save/load private and public variables of the class, so when the pointers of the old version and new version are swap the new pointer has the same data and status as before.

Example

  • Is not a real example, just to illustrate.
  • A character jumps and it’s on the air in the middle of the jump animation with enum state JUMPING in a state machine.
  • Hot Reload happens.
  • A character continue at the same state as even private variables are restored automatically, just now have a nice FIRE particles.

It’s not the end of the world if the object it’s reset, but that allows you to have no need to restart the whole scene as other objects depends on the data of that character, and many etc.

Thanks for your answer and support.

PS: I’m trying to achieve an official and free community integration for all the Ly fans

Hi! I have experience of integrating similar system to LY, and I chose to limit the experience to updating methods and functions only.

When it comes to updating components’ data, that gets very tricky and challenging for the following reasons:

  1. You cannot add/remove components in active entities. Even if you were to hook in and swap out pointers inside AZ::Entity component storage, you would run into the following challenge:
  2. Components communicate between each other using EBuses https://docs.aws.amazon.com/lumberyard/latest/userguide/ebus-intro.html , the communication in EBuses is done by components connecting to EBuses and EBuses storing pointers to components, so you would have to fix up EBus component storage as well when you reload a new component in a different memory.
  3. Additionally, LY uses reflection system for the components. This data gets processed at load/startup time (inside Asset Processor https://docs.aws.amazon.com/lumberyard/latest/userguide/asset-pipeline-processor.html ). This is done through ::Reflect() method of each component, see https://docs.aws.amazon.com/lumberyard/latest/userguide/component-entity-system-reflect-component.html
    That is not re-calculated during runtime or even during editor time. You could update private component date that but will not reflect in the Editor, until you re-start both Asset Processor and the Editor.
  4. On top of that, if you were to get past all that and update the component in place, and start working in the editor, what happens when you save a change in there? Well, the Editor would make the change to a slice or the level, and tell the Asset Processor to save that change to the disk. So now you would be using a different serialization data at runtime that has changed since the startup time. In general, we provide versioning to handle this offline: “serialize->Class<MyComponent, AZ::Component>()->Version(1)”. But with a serialization changing at runtime that gets tricky, as you have to careful not to destroy your data, since the hotload doesn’t stay around when the application and Asset Processor are closed.

All in all, there are a number of challenges for the full experience, but I found that even hotpatching method and functions is an awesome time saver. I would advise breaking the work into two parts:

  1. just general method hotload
  2. and then tackle memory hotload

Good luck!

1 Like

Thanks for that complete answer @MrOleksandr, appreciated!