Skip to content

Game.Prefabs.HoveringObject

Assembly:
Game

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
Component used on prefab definitions to make placeable objects hover above the ground. When applied, it adjusts the PlaceableObjectData on the entity: sets a vertical placement offset (m_HoveringHeight) and flips placement flags so the object is treated as hovering rather than placed on the ground. The component appears in the editor ComponentMenu under "Objects/" and is intended for use with StaticObjectPrefab and MarkerObjectPrefab prefabs.


Fields

  • public float m_HoveringHeight
    Height (world units) above ground at which the object should hover. During initialization this value is written into PlaceableObjectData.m_PlacementOffset.y so the entity will be positioned that many units above ground.

Properties

  • This class declares no properties.

Constructors

  • public HoveringObject()
    No explicit constructor is defined in the source; default parameterless constructor is used. Typical usage is via prefab/component instantiation in the editor or prefab pipeline.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds required component types to the prefab's component set. Implementation adds PlaceableObjectData (ReadWrite) because the hovering behavior modifies that component at initialization.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Override present but empty — this component does not add archetype-only components.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab component is initialized on an entity. Implementation:

  • Calls base.Initialize.
  • Reads PlaceableObjectData from the entity.
  • Sets componentData.m_PlacementOffset.y = m_HoveringHeight.
  • Clears the PlacementFlags.OnGround flag and sets PlacementFlags.Hovering.
  • Writes the modified PlaceableObjectData back to the entity. This ensures the object will be placed at the specified hover height and treated as a hovering object by placement systems.

Usage Example

// Example: set up a hovering prefab via inspector or script
[ComponentMenu("Objects/", new Type[] { typeof(StaticObjectPrefab), typeof(MarkerObjectPrefab) })]
public class MyHoveringPrefab : HoveringObject
{
    void Reset()
    {
        // default hover height when creating the prefab in editor
        m_HoveringHeight = 2.0f;
    }
}

// Runtime: Initialize will be called by prefab system. Internally it will:
// - ensure PlaceableObjectData exists on the entity
// - set the vertical placement offset to m_HoveringHeight
// - mark the object as hovering (clear OnGround, set Hovering)

Notes for modders: - Ensure the prefab also includes PlaceableObjectData (GetPrefabComponents adds it automatically). - The effect takes place during Initialize, so any systems relying on placement flags should run after initialization. - m_HoveringHeight is in world units; adjust to fit the model scale and desired clearance above terrain/roads.