Skip to main content

Interface IDataLoggable

Contract for any MonoBehaviour component that wants to contribute data to the analysis pipeline.

public interface IDataLoggable

Examples​

// Implement IDataLoggable on a MonoBehaviour to expose actor speed for logging:
public class SpeedLoggable : MonoBehaviour, IDataLoggable
{
[SerializeField] private Rigidbody _rigidbody;

public DataLog Collect()
{
if (!enabled) return null;
var log = new SpeedDataLog();
log.speed = _rigidbody.velocity.magnitude;
return log;
}
}
// Place both this component and a DataCollector on the actor's hierarchy.
// DataCollector will call Collect() automatically when analysis data is requested.

Remarks​

By implementing this interface, a component opts into being discovered and polled by the nearest ancestor DataCollector in the scene hierarchy. This design keeps individual components loosely coupled from the analysis system: a component does not need to know about the collector, and the collector does not need to enumerate specific component types — it simply finds all IDataLoggable children at startup.

Collect returns the base DataLog type so the collector can store heterogeneous snapshots (BatteryDataLog, TransformDataLog, …) in a single list without knowing each concrete type in advance.

Properties​

gameObject​

The GameObject this component is attached to.

GameObject gameObject { get; }

Property Value​

GameObject

Remarks​

Declared in the interface so that DataCollector can call GetComponentInParent() on it to verify hierarchy ownership without needing a separate reference. MonoBehaviour subclasses satisfy this automatically — no implementation is needed.

Methods​

Collect()​

Captures a snapshot of this component's current state and returns it as a DataLog subclass.

DataLog Collect()

Returns​

DataLog — A DataLog subclass populated with the component's current readings, or null if no data is available.

Remarks​

Return null when the component has no meaningful data to contribute (e.g., it is disabled or in an initialising state). The collector ignores null returns and excludes them from the analysis output, so implementations never need to allocate a placeholder.