[Solved] Programmatically setting a property is not persisted between saves

nategovannategovan Posts: 35

Hi,

Bit of a strange one, I'm obviously doing something wrong but not sure what.

Context and Problem

I want to persist some meta-data (config, eg, a small json string). Storing it as an property in the scene graph seems logical but it is not persisting when saved and reloaded. Manually creating the property in the GUI does persist between saves and reloads. General code is as follows:

var NG_PROPERTY_NAME = 'EXAMPLE CONFIG'var NG_PROPERTY_FOLDER = 'EXAMPLE PATH'function setConfig(data) {    var node = Scene.findNodeByLabel(NG_PROPERTY_NAME)    if (node === null) {    	node = new DzNode()    	node.setName(NG_PROPERTY_NAME)    	node.setLabel(NG_PROPERTY_NAME)    	node.setVisible(false)    	Scene.addNode(node)    }	var prop = node.findProperty(NG_PROPERTY_NAME)	if (prop === null) {		prop = new DzStringProperty(NG_PROPERTY_NAME)		prop.name = NG_PROPERTY_NAME		prop.setLabel(NG_PROPERTY_NAME)		prop.setPath(NG_PROPERTY_FOLDER)		node.addProperty(prop, true)	}	prop.setValue(JSON.stringify(data))}setConfig({hello:'world'})

 

Current outcome - The EXAMPLE_PATH/EXAMPLE CONFIG DzStringProperty is not persisted when the scene is saved and reloaded.

Desired outcome - The EXAMPLE_PATH/EXAMPLE CONFIG DzStringProperty IS persisted when the scene is saved and reloaded.

Questions

  • Are there any faults in the code?
  • Are there any better / more proven ways of persisting easily purgable meta information in a standard saved file? I have generally been writing config to the windows AppData directories, but in this specific context, having data associated with the scene .duf makes a lot more sense.

Thanks

Post edited by nategovan on

Comments

  • OmnifluxOmniflux Posts: 377

    You probably want to be using DzSceneData instead.

  • OmnifluxOmniflux Posts: 377

    To solve your issue as is, however, you need to set your property as a user property

    Replace

    		prop = new DzStringProperty(NG_PROPERTY_NAME)

    with

    		prop = new DzStringProperty(NG_PROPERTY_NAME, true)

     

  • Perfect and perfect. Thanks @Omniflux. This was what I was looking for on both question.

Sign In or Register to comment.