πObject Placement
Detailed information about the component's interface and its use.
Overview
The ObjectPlacement
class manages the placement of objects within a scene in Unity. It provides tools to precisely place, rotate, and align objects based on user input or predefined settings. This component is essential for the use of this asset.
Runtime
Properties
This can all be configured in the Editor. For Runtime changes you can set these properties when needed/available:
Instance: Singleton instance of the
ObjectPlacement
. Ensures only one instance is active using the Singleton pattern.PlacementObjectPrefab: The prefab used for placement operations. Can be set dynamically when not actively placing an object.
PlayerCamera: The main camera used for rendering the world to the player, crucial for calculating placement positions from screen points.
PlacementArea: Defines the area within which objects can be placed, potentially restricting placement outside a designated zone. See Placement Area for more information.
PlacementPrefabs: Specifies a component that holds a list of placement prefabs, this will return
null
when component is not set up.AdditionalValidator: Validator invoked after internal validation has been performed with a valid result, if result is invalid this will not be invoked. Only already valid placements can be rejected by this validator. By implementing IValidatePlacement you can integrate a more complex system of your project giving it one additional validation layer.
debugLogsEnabled: Specifies if the console logging is enabled.
drawGizmosEnabled: Specifies if the gizmos for placement are enabled.
Public Interface
BeginPlacement(GameObject prefab, Material[] validPlacement, Material[] invalidPlacement): Initiates the placement of a specific prefab with optional materials to indicate valid or invalid placement states.
BeginPlacement(): Initiates the placement of current prefab and material configuration.
CancelPlacement(): Cancels the current placement operation and removes any temporary placement objects.
TryEndPlacement(out GameObject newInstance): Attempts to finalize the placement of the current object, returning true if successful along with the newly placed object.
TryEndPlacement(out PlacementResult result): Attempts to finalize the placement of the current object, returning true if successful along with the result of the placement (position and rotation).
RotateObjectYAxis(float yAngle): Rotates the currently placing object on the Y-axis by the specified angle.
RotatePlacement(float directionalMagnitude): Rotates currently placing object on Y axis by multiplying directional magnitude parameter with
rotationSpeed
.
Editor
Here you can read about how to use the component inspector in Editor to set up it's configuration for your needs.
You should use this tab to configure behaviour of the component. You can reference camera and prefab directly from Editor or use component's public interface to achive this in code.
Hover over each field to read more about their use.

Last updated