void SetParent( GameObject value, bool keepWorldPosition )

robot_2Generated
code_blocksInput

Description

The SetParent method allows you to set a new parent for the current GameObject. This operation can optionally maintain the world position of the GameObject when changing its parent.

Usage

To use the SetParent method, call it on an instance of GameObject and pass the new parent GameObject as the first parameter. The second parameter is a boolean that determines whether the GameObject should keep its world position after the parent change.

If keepWorldPosition is set to true, the GameObject will maintain its current position in the world space, even though its local position relative to the new parent might change. If set to false, the GameObject will move to a new position relative to the new parent, effectively changing its world position.

Example

// Example of using SetParent
GameObject childObject = new GameObject();
GameObject newParentObject = new GameObject();

// Set newParentObject as the parent of childObject
// and keep the world position of childObject
childObject.SetParent(newParentObject, true);