Entity Hierarchy (parenting)

From Valve Developer Community
Revision as of 15:49, 21 April 2018 by Marvin (talk | contribs) (Grammar.)

Jump to: navigation, search
Русский 日本語 简体中文

When a group of entities are parented together, they form a rigid movement hierarchy family which will move together as if all the entities were one physical object. Each child-entity will follow its parent's movement.

A simple example would be parenting a light_dynamic to a lamp prop so the light becomes part of the lamp and moves with it.

The child-parent relationship is always defined in the object properties of the child-entity. The parent-entity doesn't have any say in choosing its followers. This leads to the rather awkward use of 'parenting' as a reflexive verb throughout the documentation, eg "must be parented", "parent the child to the parent", "entities can have parents", etc.

Only certain entities can have parents. For example, a prop_physics cannot because it is its own physics object (however all entities can actually be parented if the 'parentname' keyvalue is added, though not all will function correctly). In this case, use a prop_dynamic or prop_dynamic_override instead, or use an info_constraint_anchor to link up with the physics constraint system.

  • The Offset is the distance (and any rotational offset) between the Child and Parent entities at the time the relationship is activated. Whilst the offset is maintained, the Child will move parallel to its parent's movements, and "orbit" the parent's origin at the offset distance when the parent rotates. Only the SetParentAttachment input changes the offset; it instantly "teleports" the child to the parent's attachment point and holds it there instead.
  • Collision : The Child's Solidity is suspended whilst it is parented. It will pass through walls and other solid objects.
  • If the Parent is Killed, all of its current Children are also removed from the game.

Parentname

To create a child-parent relationship between two entities, set the child-entity's parentname keyvalue to the parent-entity's targetname.

  • Maintains offset.
    Bug: The parent field does not work correctly for some entities in CS:S. Instead, use a logic_auto and call SetParent at the start of the map
    Bug: Children may lost their parents on HL2:DM Linux Dedicated Server. So, it's highly recommended to use a logic_auto and use output "OnMapSpawn child SetParent parent"
  • Additionally, an attachment point can be set by setting the value to parent,attachment. This behaves like SetParentAttachmentMaintainOffset.

SetParent

You can also fire a SetParent input at the child-entity to change it's child-parent relationship.

  • Use the targetname of the new parent as the input parameter to make the child follow the new parent.
  • If you leave the parameter blank, it has the same effect as the ClearParent input (see below).
  • Maintains offset.

SetParentAttachment

Note:Entities must be parented before being sent this input. Use at least a 0.01 second delay between SetParent and SetParentAttachment inputs.

You can also fire a SetParentAttachment input at the child-entity to attach it to a specific attachment point on its parent. The parameter is the name of the attachment point.

  • The Child instantly teleports to the attachment point. This is the only method which does not maintain the offset.

SetParentAttachmentMaintainOffset

Note:Entities must be parented before being sent this input. Use at least a 0.01 second delay between SetParent and SetParentAttachmentMaintainOffset inputs.

You can also fire a SetParentAttachmentMaintainOffset input at the child-entity to attach it to a specific attachment point on it's parent. This works exactly the same as the SetParentAttachment input except the child-entity will maintain it's relative position to and distance from the parent at the time it is attached.

  • Maintains offset, but the Child shadows/orbits the attachment point position instead of the parent's EntityOrigin.
Note:You can parent an entity directly to an attachment point by putting a comma to separate the parent's name and the attachment point. The offset will be maintain
Example : Combine_Dead_Ragdoll,anim_attachment_RH

ClearParent

You can also fire a ClearParent input at the child-entity to remove its child-parent relationship. This simply 'unparents' or 'detaches' the child-entity from its current parent, so the child is then free to move (or not) independently of its former parent.

KillHierarchy

Note:This is the only movement hierarchy-related input that can be fired at the parent-entity.

If you fire a KillHierarchy input at the parent-entity, it Removes the parent-entity and all of its children from the world.

  • If you fire a Kill input at the parent-entity, it also Removes the parent-entity and its children from the world ... ?
Bug: If you have a point_spotlight child of another entity, and you kill the parent entity without removing the point_spotlight using an input, it will spawn in the center of the map (0,0,0) facing north.

FollowEntity()

Programmers can use FollowEntity() to control parenting.

Tutorials about PARENT (Russian)

Lessons created by Project-S

All about Parent (Всё о Parent)