Skip to content

Game.Prefabs.PlantObject

Assembly: Game
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Represents a plant/plantable object prefab component used by the game's placement and entity systems. This component contributes what runtime components and archetype components a plant prefab requires (PlantData, Plant, UpdateFrame) and performs late initialization to adjust placement behavior when m_TreeReplacement is enabled. It is typically used for plant/decoration prefabs (trees, potted plants, etc.). {{ This component ensures the correct ECS components are requested for plant prefabs and, if configured, marks the object as a tree replacement except when placed on road nodes/edges. }}


Fields

  • public System.Single m_PotCoverage
    {{ Fractional coverage value (float) related to pot/placement area for this plant prefab. Likely used by placement or rendering logic to determine how much area the plant occupies when in a pot or similar placement configuration. }}

  • public System.Boolean m_TreeReplacement
    {{ When true, the prefab will attempt to act as a tree replacement: during LateInitialize the code will set the PlaceableObjectData.m_SubReplacementType to SubReplacementType.Tree unless the object is placed on a road node or road edge. This enables prefab trees to be used as replacements in systems that reference SubReplacementType. }}

Properties

  • None
    {{ This class does not declare any properties. All state is provided via public fields and by the overridden methods that configure ECS components. }}

Constructors

  • public PlantObject()
    {{ Implicit default constructor. Instances are typically created/instantiated by the prefab/component system rather than by direct construction in user code. }}

Methods

  • public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    {{ Adds the runtime prefab component requirement: ComponentType.ReadWrite(). This tells the prefab/system that entities created from this prefab need a PlantData component. }}

  • public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    {{ Adds ECS archetype component requirements for spawned/instantiated entities: ComponentType.ReadWrite() and ComponentType.ReadWrite(). These ensure the entity archetype includes the Plant component and an UpdateFrame component for per-frame updates. }}

  • public override void LateInitialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
    {{ Performs late initialization once the prefab's entity exists. Behavior:

  • Calls base.LateInitialize(entityManager, entity).
  • If m_TreeReplacement is true and the entity has a PlaceableObjectData component, and that PlaceableObjectData's flags do not include PlacementFlags.RoadNode or PlacementFlags.RoadEdge, then it sets PlaceableObjectData.m_SubReplacementType = SubReplacementType.Tree and writes the component back to the entity. This effectively marks the object as a tree replacement for placement/substitution systems except when placed on road nodes/edges. }}

Usage Example

// Example: subscribing to or tweaking a PlantObject instance at runtime (conceptual).
// Prefabs are normally created by the game; you can adjust fields on your prefab instance.

[Preserve]
public class CustomPlantSetup
{
    public void ConfigurePlantPrefab(PlantObject plantPrefab)
    {
        // Increase pot coverage, enable tree replacement so it's used as a tree substitute
        plantPrefab.m_PotCoverage = 0.75f;
        plantPrefab.m_TreeReplacement = true;
    }
}

// The PlantObject.LateInitialize override will run during the prefab/entity initialization phase.
// If m_TreeReplacement is true and placement flags allow, the entity's PlaceableObjectData.m_SubReplacementType
// will be set to SubReplacementType.Tree.