Game Development Community

Retaining object linkage on dynamic objects

by Andy Schatz · in Torque Game Engine · 12/11/2008 (10:39 am) · 2 replies

I've got a game object (animal) that has a pointer (SimObjectPtr to be exact) to another object, its nest. When I save the game, I am just saving out the objects to a script file in the standard way. When I reload that save file, I want to make sure the animal retains its linkage to its nest.

The problem is that these objects are dynamic, so I can't just name them in the editor. And when I reload the objects, their id's will change. Is there a standard way for one object to keep track of another object without naming it or using its id?

I'm looking for a generic solution here, since this sort of problem happens in a number of cases (saving the camera state, etc). Any ideas?

#1
12/11/2008 (12:00 pm)
I ran into a similar problem a while back. The solution i came up with was to create a little naming scheme for a particular object type(like nest1 nest2 nest3 ect...). And just had it automatically name the objects as I add them. I used a script object to keep track of what number i was up to and to store the values for any objects that get deleted so i wouldn't have the numbers climbing into the sky if i had to add and remove objects repeatedly and of course made sure to save that script object to the file as well. The script object was not really that much of a burden either because it gave me a useful place to store other specfic variables relating to the file. it actually works pretty well.

Probably the absolute simplest way to do what your wanting.
#2
12/11/2008 (12:05 pm)
Wesley, thanks for the reply! I thought I knew a problem with this solution, but then I thought about it some more and I think you're right, this does work. Thanks!