set Parent in the runtime

I am fixing my own editor to add the feature setting an object's parent in the runtime;

but I use orxObject_SetParent to realize this feature
but it always triggered an error said:

[2011-05-05 16:39:37] <SYSTEM> (orxTree_MoveAsChild() - home/laschweinski/android/workspace/liborx_svn/code/src/utils/orxTree.c:479) Graph cycle found, invalid move.

so how to set the parent of an object in the runtime?
and what is difference between orxObject_SetParent and orxObject_SetOwner

when I use orxObject_SetOwner, there is no any error, but seems no any result I want to get.

[Edit]I have solved this....I made some mistake. but still want to know what is difference between orxObject_SetParent and orxObject_SetOwner


  • edited May 2011
    So as you probably found out you can't have a cycle in the parent hierarchy: it's a tree, not a graph. So thing like:

    A parent of B parent of C parent of A => invalid

    orxObject_SetOwner() isn't really of any interest for end users, it's the way some structures can assert their ownership on an object, such as a spawner on spawned objects or an object on his ChildList: ChildList actually sets both: Parent so as to get a hierarchy and Owner, so that the main objects will destroy the ones created through ChildList when he gets deleted.

    So basically, you shouldn't have to use orxObject_SetOwner() unless you know what you're doing. It's mostly reserved for orx's internal needs.
  • edited May 2011
    so I tried that:
    when using orxObject_SetParent(A, BBB);
    then I try to get A's parent by using orxObject_GetParent. its parent is not BBB (is NULL or other)

    but when I add
    orxObject_SetOwner(A, BBB);
    its parent is BBB

    but when I want to get B's child by orxObject_GetChild, there is no any A.

    Now I want to get the children so as to store the child list in the config.
    is this result what you design to?
    if yes, I will add some more extra structure in my editor to realize the feature.
    Thank you
  • edited May 2011
    I know why it happened you forgot to update the flag in orxObject_SetOwner
    By adding
    /* Updates flags */
    orxStructure_SetFlags(pstObject, orxOBJECT_KU32_FLAG_CHILD, orxOBJECT_KU32_FLAG_NONE);

    it would be fine.

    but do you on purpose to forget to update the flag?

    Besides, I found query the child is really a low-performance operation. have to find a child in all of object. if there are lots of objects, to find only one child would be a tough task that will waste some time. is it necessary to add a childlist to the object structure?
  • edited May 2011
    So yes, this flag isn't set on purpose. An owner of an orxOBJECT doesn't have to be an orxOBJECT (like an orxSPAWNER, for example). In those case, the child flag has no meaning.

    What that flag means is that an object has been created through the config option ChildList, and only this way.

    orxObject_GetChild()/_GetSibling() is linked to that ChildList option, it's not linked to the hierarchical frame parenting (orxObject_SetParent()).

    I know that the names are confusing but I couldn't come with better ones.

    The SetParent()/GetParent() accessors only refer to the tree hierarchy of the internally stored orxFRAMEs whereas GetChild()/GetSibling() (and, in this case, GetOwner()) refers to the ChildList feature.
    GetOwner() has also other uses outside the ChildList feature.

    As for performances, you're right when you say that we have to go through all the objects and that it might not be very efficient. However calling the GetChild()/GetSibling() hasn't been intended to be a frequent operation (orx uses it mainly when deleting an object so as to delete its children).
    We could add two pointers to the object structure but I found the structure to be big enough (and the calls to GetChild()/GetSibling() to be rare enough) and decided to go this way.

    Does it answer your questions?
  • edited May 2011
    In default the object will scale with its parent object.
    but how to make child object only use parent position but do not use its scale

    I try to set useParentSpace = position in config in child object, but it seems there is no result I want to get.
  • edited May 2011
    When you use parenting for objects/spawners/camera, you inherit from all the parent's frame info. That includes position, scale and rotation. You can't pick only some of them: using parenting means that the child coordinates are expressed in the parent's space.

    Regarding the UseParentSpace feature, here what's the wiki says:
    UseParentSpace: If set to true and the object has a valid parent orxCAMERA 3), its position and scale will be considered in parent's space, ie. values between 0.0 and 1.0

    It only affects objects that have an explicit ParentCamera field in their config section.

    Now if you want to inherit the position and not the scale, I advise you to use a 3 nodes hierarchy instead of a 2 ones:
           DummyObj <- Do your SetPos here
    MainObj(+scale)  Your other child (without MainObj's scale)
Sign In or Register to comment.