Page 1 of 1

set/unset parent

Posted: Tue Jan 24, 2017 8:12 pm
by D3CEPTION
im trying to unset a parent to an entity after setting it this way:

Syntax: Select all

ent.set_parent(parententity.pointer)


this is how i would think to remove it, but doesnt work:

Syntax: Select all

ent.set_parent(Entity(0).pointer)


error is:

Code: Select all

Exception ignored in: <bound method __del__ of <entities.helpers.EntityMemFuncWrapper object at 0x2E838BC0>>
TypeError: No registered converter was able to extract a C++ pointer to type class CPointer from this Python object of type EntityMemFuncWrapper


my previous working method was this:

Syntax: Select all

parententity.targetname = "name"
ent.call_input("SetParent",parententity.targetname)
ent.call_input("SetParent","")

Re: set/unset parent

Posted: Tue Jan 24, 2017 8:17 pm
by D3CEPTION
will ent.clear_parent() remove the parent?

Re: set/unset parent

Posted: Tue Jan 24, 2017 8:22 pm
by D3CEPTION
okay clear_parent() actually does remove the parent correctly. the error i had was due to not setting the .model_name

Re: set/unset parent

Posted: Wed Jan 25, 2017 12:33 am
by L'In20Cible
You can directly pass an Entity instance to set_parent, no need to retrieve its pointer yourself.

Re: set/unset parent

Posted: Wed Jan 25, 2017 2:10 am
by D3CEPTION
is it also possible to check for a parents entity existance?

like this:

Syntax: Select all

if ent.parent:
print("ent has parent")


Syntax: Select all

if ent.get_parent():
print("ent has parent")

Re: set/unset parent

Posted: Wed Jan 25, 2017 2:16 am
by satoon101
We don't currently have parent in our entity data, but one of these properties will probably work (all a part of CBaseEntity). I'm unable to test, currently.

Code: Select all

    m_Network.m_hParent
    m_iParent
    m_pParent

Re: set/unset parent

Posted: Wed Jan 25, 2017 2:25 am
by D3CEPTION
yeah, im looking through some old code too where i used ent.get_property_int("m_pParent"). its btw returning the inthandle/-1.

might be worth adding .parent as playerentity imo

Re: set/unset parent

Posted: Wed Jan 25, 2017 2:27 am
by L'In20Cible