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
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
..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
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
About the author
#2
I guess the right way of achieving this would be to have named linkpoints, e.g.
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)?
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
Then in you can do
In some other file you have
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:
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.
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.
Torque Owner Ben R Vesco