Game Development Community

Issue with names of mounted objects

by Matias Kiviniemi · in Torque X 2D · 02/27/2007 (12:12 pm) · 3 replies

Hi,

I have an object (lets say "OBJ") with three mounted objects (lets say "MOUNT1-3"). All of them are T2DStaticSprite and have the name property set in TGBX (to OBJ/MOUNTx). What I want to do is keep reference to the mounted objects in a component of OBJ. So in _InitComponent I do the following

List<T2DSceneObject> mounts = new List<T2DSceneObject>();
_owner.GetMountedObjects("*", mounts);

This gives references to the three mounted objects, but for some reason the names are empty (i.e. mounts[i].Name == ""). But if I access the mounted objects from the DB (there are no other objects with that name), for example

T2DSceneObject mount = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("MOUNT1");

..the names are correct. One thing I noticed is that while debugging with GSE, the two methods give references with different AutoName-properties (different numbers). If I understand correctly, both ways should produce same results..

Matias

#1
02/27/2007 (6:26 pm)
If your objects are getting copied or cloned somewhere along the way then they won't have the same .Name property anymore. It is fairly typical that your code does not use the object from the scene directly but calls a .Clone on the template. If you are using templates and/or spawn objects then your names won't be copied. Only the original, deserialized version of the object has the given name. Does that get you pointed in the right direction?
#2
02/28/2007 (2:03 am)
I don't think cloning is the problem in this case. The object with mounts is the "original from .txsene" (not marked as template or cloned). But you raise a valid point that using .Name to identify mounts is not a good idea because it won't work with cloned objects.

I guess the right way of achieving this would be to have named linkpoints, e.g.

T2DSceneObject mount1 = _owner.GetMountedObject("mount1Linkpoint");

It's just that the beta of TGBX doesn't allow assigning names to linkpoints, but they become "LinkPointN". Using them makes code messy, and I wanted to have an identifiable name to use. Do you know if it's possible to manually add the .Name-properties to LinkPointComponent same way you can introduce your own components to TGBX (while waiting 1.0)?
#3
02/28/2007 (10:30 am)
What I did was to create identifiable code constants that could later be changed to the right values. In a globally accessible file named Constants.cs or whatever you think is a good place or name:

public static readonly String HAT_LINK_POINT = "LinkPoint1";
public static readonly String GUN_LINK_POINT = "LinkPoint2";
public static readonly String BOOT_LINK_POINT = "LinkPoint3";

Then in you can do

T2DSceneObject hat = _owner.GetMountedObject(Constants.HAT_LINK_POINT);

In some other file you have

T2DSceneObject gun = _owner.GetMountedObject(Constants.GUN_LINK_POINT);

and so on. Then when you get the ability to name link points in TGBX you can just open that one Constants.cs file and change:

public static readonly String HAT_LINK_POINT = "HatMount";
public static readonly String GUN_LINK_POINT = "GunMount";
public static readonly String BOOT_LINK_POINT = "BootMount";

This gives you relevant, english names for your mount points in code and allows you to change them all to meaningful names in TGBX when the ability is there. Keeping them all in one place makes it even easier to change them instead of searching through code for the points of usage.