Skip to content

Game.Simulation.XPGain

Assembly:
Assembly-CSharp (game's main managed assembly; may vary by build)

Namespace:
Game.Simulation

Type:
struct

Base:
System.ValueType

Summary:
Represents an XP (experience) change directed at a specific Entity. This plain data struct packages the target Entity, the integer amount of XP to add (or remove if negative), and a reason code (XPReason) describing why the XP change occurred. Typically used as a lightweight event/DTO that systems can queue, process, or attach to entities depending on your ECS design.


Fields

  • public Unity.Entities.Entity entity
    The target Entity that should receive (or lose) the XP. This is a Unity.Entities.Entity struct identifying the game object in ECS.

  • public int amount
    The amount of XP to change. Positive values indicate granting XP; negative values indicate removing XP. Interpretation (e.g., clamping or multipliers) is handled by the system that processes XPGain instances.

  • public XPReason reason
    An enum value describing why the XP was granted (for example: Combat, MissionComplete, Building, etc.). The XPReason enum is defined elsewhere in the codebase and is used by systems to apply different logic or logging per reason.

Properties

This type has no properties.

Constructors

  • public XPGain()
    Default value-type constructor (zeroed fields). You can create instances via the default constructor and object initializers; no explicit constructors are defined in the source.

Example:

var xp = new XPGain { entity = playerEntity, amount = 50, reason = XPReason.MissionComplete };

Methods

This type defines no methods.

Usage Example

Basic usage as a simple value/event object:

// Create an XPGain event and add it to a list for processing by a system
var xpEvent = new XPGain
{
    entity = playerEntity,
    amount = 100,
    reason = XPReason.Combat
};

var xpList = new NativeList<XPGain>(Allocator.Temp);
xpList.Add(xpEvent);

// Later, a system iterates xpList and applies XP to the entities.
// Remember to Dispose xpList when done.

If you intend to treat XPGain as an ECS component, implement the appropriate ECS interface (for example IComponentData) or wrap it in a component container before adding it to entities:

// Example if changed to an ECS component:
// public struct XPGain : IComponentData { ... }

entityManager.CreateEntity(typeof(XPGain));
entityManager.SetComponentData(eventEntity, xpEvent);

Notes: - XPGain is a plain value type; how it is transported and processed (collections, entities, jobs) is up to your mod/system design. - Ensure thread-safety and allocator usage when using Native collections or scheduling jobs that reference XPGain instances.