Game.Prefabs.PlaceholderObject
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Prefab component used by the prefab-to-entity conversion system to mark an object as a "placeholder" and to supply placeholder-related ECS components (PlaceholderObjectElement, PlaceholderObjectData and the archetype component Placeholder). It also copies the inspector-configured m_RandomizeGroupIndex value into the entity's PlaceholderObjectData. The ComponentMenu attribute places this component in the editor menu under "Objects/". Intended for use in Cities: Skylines 2 mod prefab creation and conversion to ECS entities.
Fields
public System.Boolean m_RandomizeGroupIndex
Controls whether the placeholder should randomize its group index when converted to an entity. Value is serialized on the prefab and transferred into the PlaceholderObjectData component in Initialize().
Properties
- (none)
Constructors
public PlaceholderObject()
Implicit default constructor. Instances are normally created by the Unity editor when adding the component to a prefab.
Methods
public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds prefab-component types required on the entity instance created from this prefab. This implementation adds:- PlaceholderObjectElement
-
PlaceholderObjectData These are added as readable/writable component types so the entity has the necessary data/element components at instantiation.
-
public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds archetype-level components required for entities created from the prefab. This implementation adds the Placeholder component (ComponentType.ReadWrite), which affects the entity archetype. -
public override void Initialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Called during prefab-to-entity initialization. Behavior: - Calls base.Initialize(entityManager, entity).
- If the prefab has a SpawnableObject component, logs a warning (PlaceholderObject used on a spawnable prefab).
- Constructs a PlaceholderObjectData instance using the inspector-configured m_RandomizeGroupIndex and writes it to the entity via entityManager.SetComponentData(entity, componentData). Notes: The method expects that PlaceholderObjectData struct and PlaceholderObjectElement components exist and are compatible with SetComponentData/read operations.
Usage Example
// Typical usage: add PlaceholderObject to a prefab in the editor and configure m_RandomizeGroupIndex in the inspector.
// During conversion the Initialize method will run and write the PlaceholderObjectData to the entity.
// Example: read back PlaceholderObjectData after conversion (runtime/system code)
void OnSomeSystemUpdate(EntityManager em, Entity placeholderEntity)
{
if (em.HasComponent<PlaceholderObjectData>(placeholderEntity))
{
var data = em.GetComponentData<PlaceholderObjectData>(placeholderEntity);
Debug.Log("Randomize group index: " + data.m_RandomizeGroupIndex);
}
}
Notes and tips: - The component emits a warning if combined with SpawnableObject; check prefab composition to avoid unintended behavior. - Ensure the companion ECS types (PlaceholderObjectElement, PlaceholderObjectData, Placeholder) are present in your mod's code so the entity conversion succeeds.