Storing / retreiving a custom control

Hello,



I’ve got the following two methods in my control:



[java]

@Override

public void read(JmeImporter im) throws IOException {

super.read(im);

InputCapsule ic = im.getCapsule(this);

System.out.println(getSpatial());

template = ENTITY_TEMPLATES.valueOf(ic.readString(“template”, null));

template.getEntityTemplate().setSpatial(getSpatial());

}



@Override

public void write(JmeExporter ex) throws IOException {

super.write(ex);

OutputCapsule oc = ex.getCapsule(this);

oc.write(template.name(), “template”, null);

}

[/java]



This is on my Control which in turn extends AbstractControl. In here, I first call the corresponding supre methods, which in turn should write / read the spatial in the control. But in the read method, the System.out returns null for the getSpatial…



Anyone have any idea what could be causig this, and how I fix it?



Mark

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:save_and_load

getSpatial returns the spatial on wich the control is attached. the control is not yet attached when the read method is called.*

You must call

[java]

template.getEntityTemplate().setSpatial(spatial);

[/java]

in the setSpatial method of your control. (just override it)