Skip to content

Game.Prefabs.TreeData

Assembly:
{{ This type is part of the game's runtime modding assemblies. If you are compiling a mod project, place this file in the mod assembly that references Colossal.Serialization and Unity.Entities. }}

Namespace: Game.Prefabs

Type:
struct (value type)

Base:
System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
TreeData is a small ECS component used to store the amount of wood contained in a tree instance. It is a plain, blittable struct with a single float field and provides serialization support via the Colossal.Serialization ISerializable pattern so tree wood amounts can be persisted and loaded by the game's serialization system. This component is intended to be attached to entity representations of trees in the game's ECS.


Fields

  • public float m_WoodAmount
    Represents the amount of wood available from the tree. Stored as a single-precision float. Default value is 0.0f for newly created instances. This value is serialized/deserialized by the implemented ISerializable methods.

Properties

  • This type has no properties. (It exposes a public field instead.)

Constructors

  • public TreeData()
    Implicit default constructor provided by C#. Initializes m_WoodAmount to 0.0f. You can create initialized instances via object initializer syntax, e.g. new TreeData { m_WoodAmount = 50f }.

Methods

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the single float value for m_WoodAmount from the provided reader. The reader must implement Colossal.Serialization.Entities.IReader. This method is called by the game's serialization machinery when loading component data.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_WoodAmount float to the provided writer. The writer must implement Colossal.Serialization.Entities.IWriter. This method is used by the game's serialization machinery when saving component data.

Usage Example

// Add the component to an entity and set the wood amount:
var entityManager = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity(typeof(Game.Prefabs.TreeData));

entityManager.SetComponentData(entity, new Game.Prefabs.TreeData {
    m_WoodAmount = 125f
});

// Reading back:
var data = entityManager.GetComponentData<Game.Prefabs.TreeData>(entity);
UnityEngine.Debug.Log($"Tree wood amount: {data.m_WoodAmount}");

// Example of manual serialization (normally handled by the engine's serializer):
// Assume 'writer' implements Colossal.Serialization.Entities.IWriter
var td = new Game.Prefabs.TreeData { m_WoodAmount = 80f };
td.Serialize(writer);

// And deserialization:
Game.Prefabs.TreeData loaded = default;
loaded.Deserialize(reader); // reader implements IReader

Additional notes: - Because TreeData is an IComponentData, it is intended for use with Unity's ECS (Entities) API. Use the EntityManager or systems to create, query, and modify entities with this component. - The IQueryTypeParameter implementation tag means this type can be used in query type parameter contexts (used by the game's ECS querying utilities). - The struct is small and safe to use in jobs and multi-threaded contexts, provided you follow Unity's ECS safety rules (use ComponentDataFromEntity, Native containers, or proper job parameters for parallel access).