fabre.cedric Posted November 8, 2021 Share Posted November 8, 2021 (edited) Hello, I would like to know how to update a pointer to a nodeReference in Unigine (I think i need similar function to the "Apply" button in the panel of NodeReference from Unigine Editor). For exemple, I have a Node named "toto.node" that contain a NodeReference to "test.node" that contain one mesh and one "green" Light. If I change the color of the light in "red" for exemple and save the xml "test.node" and after reload "toto.node", the light is "green". If I delete all nodes from memory with Unigine::World::getRootNodes(listOfNodes); clearNode and deleteForce, the light stay "green". (The NodeReference is never delete from memory ?) If I close the software and reload my scene the light have take the good "red" color. I have tested with setAutoReloadNodeReferences(true) but that doesn't work in my case. How to made this properly ? Thanks Edited November 8, 2021 by fabre.cedric Link to comment
cash-metall Posted November 9, 2021 Share Posted November 9, 2021 (edited) Hello! this is due to node caching. you need to call World::clearNode before reload node. however i found a small bug when node loaded by name - node stored in the cache by name when node loaded from parent noderef - node stored in the cache by GUID. so it needs to be cleaned twice. I'll add this to an internal bug tracker, but for now here's a small example with workaround: int AppSystemLogic::update() { const char * inner_name = "inner.node"; const char * outer_name = "outer.node"; if (App::clearKeyState('l')) { // load outer noderef node = World::loadNode(outer_name); } if (App::clearKeyState('k')) { // load, change and save inner noderef NodePtr inner = World::loadNode(inner_name); LightOmniPtr light = checked_ptr_cast<LightOmni>(inner->getChild(0)); light->setColorFilter(vec4(randColor())); World::saveNode(inner_name, inner); inner->deleteForce(); // clear cache by name and by GUID (outer load inner by GUID) World::clearNode(inner_name); World::clearNode(FileSystem::getGUID(inner_name).getFileSystemString()); } if (App::clearKeyState('j')) { // save transform auto t = node->getWorldTransform(); // reload node node->deleteForce(); node = World::loadNode(outer_name, 0); // 0 - load without cache // restore transform node->setWorldTransform(t); } return 1; } inner.node outer.node Edited November 9, 2021 by cash-metall add files 4 Link to comment
fabre.cedric Posted November 9, 2021 Author Share Posted November 9, 2021 Hi, Ok thanks for this explanation, that help me a lot. Link to comment
Recommended Posts