Jump to content

Saving node state using C# components vs Properties


photo

Recommended Posts

I think that one very powerful feature of Unigine's node system is the possibility to load a node at runtime in the scene with some properties, change those properties in code and then save the node to disk with the modified properties. I tested and this works quite well 

(see here https://discord.com/channels/620570438505857024/698451137526890547/803225141421015080)

Even though the C# component system uses properties underneath,  In order to have a similar behavior using C# component system is not possible as the property gets destroyed after component initialization.

The only way to solve this would be to have a node with a C# component and a separate property file for each node but maybe there's a better solution ?

 

One suggestion, add a method in the C# component system that would allow to save property at runtime , I think the code is already there in the editor PropertyGenerator code ...

thanks !

Fred

Edited by fred.naar
Link to comment

Hello, Fred.

I will think about something like ComponentSystem.restoreProperties(Node node, bool include_children) and protected Component.restoreProperty() method in components. What do you think about these names?

There are some problems like: "How it should work with world_save console command?", "What if I want to call restoreProperty several times?", "How to restore exactly the same sequence of properties on the node?" etc.

Best regards,
Alexander

Link to comment

Hi Alexander, 

thanks for the quick answer....

would restoreProperties reload the default properties ? because I am trying to achieve the contrary....

this is the pseudo code I would like to make work with properties:               

    AssetLinkNode a = new AssetLinkNode(filename);
	Node n = a.Load();
    Mycomponent c = n.GetComponentInChildren<Mycomponent>();

    // some game logic here say health is set at 100 when node is loaded (it reads from underlying Component property)
      c.health =10;
     
      bool Success = World.SaveNode(filename, n) 

      //savenode also saves the health property with value of 10, like it does for "normal" properties
      


So basically I am saving the state of the node.

I am using this for our in game editor where user can set different parameters in game and then save them to a node file which is separate from the world, as for example weather conditions in this video , I would like to be able to save the changes user sets... https://youtu.be/F5yQnsQtbWQ?t=283

 

 

 

thanks !

Fred

 

 

Edited by fred.naar
Link to comment
×
×
  • Create New...