Savable Controller reinstantiate objects that are subject for update?


I'm trying to make Controllers for my Doors.

If I save and load a Node with a Controller, the objects that are referenced inside the Controller, which are being updated by the controller, will be reinstantiated, won't they?

Then the Controller will update the new instances of the objects and not the ones in the scenegraph, right?

Or can I write read/write methods in some smart way that will allow the Controller to keep the references?

When you override the read and write methods, like in this Code, you can keep all references you need.

   public void write(JMEExporter e) throws IOException {
      OutputCapsule oc = e.getCapsule(this);
      oc.write(this.spatial, "spatial", null);

   public void read(JMEImporter e) throws IOException {;
      InputCapsule ic = e.getCapsule(this);
      this.spatial = (Spatial) ic.readSavable("spatial", null);

Yes, but won't that Spatial in your example be a new Spatial?

i guess if you serialize your Door (i guess a Node with Geometries underneath) the BinaryExporter will also serialize the Controllers associated with the Door.

At least thats how it works with animated models, which should be no different.

if you serialize the Node, all children will be automatically serialized with it. you dont have to serialize the children yourself.

The Spatial was not a child of the Node but that's beside the point.

As it so happens I will save two Spatials: Spatial1 and Spatial2. Spatial1 has a reference to Spatial2 (not as a child). Spatial1 will make calls on Spatial2.

What I'm worried about is that when I load these two the reference to Spatial2 in Spatial1 will be lost.

But if it is the way .:emp…hellg:. says that won't be a problem.

sorry, i missunderstood you.

Rik said:

But if it is the way .:emp...hellg:. says that won't be a problem.

however iam not sure about that.

No problem dhdd!

Thank you for your help!

If you save the referenced objects to the same stream/file the references are restored correctly. If you store a referenced node in one file and the controller in another file a new node will be created instead of a reference to the previously loaded one.