class TestObj { string name; } modded class MissionGameplay { ref map<int, ref TestObj> test_map = new map<int, ref TestObj>(); void MissionGameplay() { JsonSerializer js = new JsonSerializer(); string error; js.ReadFromString(test_map, "{\"10\": {\"name\": \"abcd\"}}", error); foreach(auto key, auto object: test_map) { Print(key); Print(object); } } override void OnUpdate(float timeslice) { super.OnUpdate(timeslice); foreach(auto key, auto object: test_map) { Print(key); Print(object); } } }
Expected behavior:
variable test_map should store all deserialized objects from the string until the map will be destroyed
Logs should be:
-------------(MissionGameplay method)---------------- SCRIPT : int key = 10 SCRIPT : TestObj object = TestObj<2b1910e0> ------------------(OnUpdate method)-------------------- SCRIPT : int key = 10 SCRIPT : TestObj object = TestObj<2b1910e0>
Actual behavior:
All the TestObj objects are destroyed right after the function MissionGameplay is over
Logs:
-------------(MissionGameplay method)---------------- SCRIPT : int key = 10 SCRIPT : TestObj object = TestObj<2b1910e0> ------------------(OnUpdate method)-------------------- SCRIPT : int key = 10 SCRIPT : TestObj object = NULL