Hi there ?
I'm trying to implement a run-time script editing feature into my project. However, having a (simplified example) script of:
class Main
{
float test = 10.1;
void Update(float dt)
{
test += dt;
print(formatFloat(test));
}
};
Whenever I rebuild the module, test
returns to 10.1, which I consider unwanted in my case. Please note, however, that using a script like:
float test = 10.1;
class Main
{
void Update(float dt)
{
test += dt;
print(formatFloat(test));
}
};
Issue never occurs, and after reloading the script module test contains previously incremented value.One instance of Main exists at the time (at least that's the idea), and is created via application in the exact same way described in: https://www.angelcode.com/angelscript/sdk/docs/manual/doc_use_script_class.html#doc_use_script_class_1
In order to hot-reload, I'm using the Serializer addon ( https://www.angelcode.com/angelscript/sdk/docs/manual/doc_addon_serializer.html )
- I store the module, and the main class object using the factor handle
serializer.AddExtraObjectToStore(pMainObj),
- I discard module, and try to remove all traces of it (although GC seems not to clear everything instantly),
- Build the module again from the modified file (for the sake of example let's say I just saved it over itself without changes, still triggers the reload),
serializer.Restore(module)
(module variable points to the new module at this point.)
Sadly, every time I do it, test
returns back to the initial example value of 10.1f.
I've spent noticeable time trying to debug this, and the serializer *does* seem to attempt restoring the test
var, but even though some test
value seems to be changed to the incremented one inside serializer.Restore()
, in the app it still resets somehow. It's really confusing.
A thing of note is that the value of module->GetTypeInfoByDecl("Main")->GetTypeId()
changes pre and past reload - type id gets incremented by 1. I'm afraid I have no interface to force match those.
(Update() is called from the application)