🥛 Yogurt
Async Managed Entity-Component Framework for Unity
Installation
UPM
https://github.com/Hoodrij/Yogurt.git
Yogurt requires C# 11 for best performance.
The yogurt-setup skill in Skills~ will setup every dependency you need.
If a project cannot use C# 11, add CSHARP_9 to the Scripting Define Symbols.
AI Setup
This repository is also a plugin for Claude Code and Codex. The plugin gives skills that tell an agent how to build a game with Yogurt.
Claude Code:
/plugin marketplace add Hoodrij/Yogurt
/plugin install yogurt@yogurt
Codex: add this repository as a plugin marketplace, then install the yogurt plugin.
The skills are in Skills~. Unity does not import this folder.
Examples
Overview
🏷️ Entity
An Entity is nothing more than storage for components.
Entity entity = Entity.Create();
Assert.IsTrue(entity != Entity.Null);
Assert.IsTrue(entity != default);
Assert.IsTrue(entity.Exist);
entity.Kill();
Assert.IsFalse(entity.Exist);
🏷️ Component
Components are types containing data.
public class Health : IComponent
{
public int Value;
}
public record struct HealthStruct(int Value) : IComponent;
Entity has a bunch of methods to operate with components.
entity.Add(new Health());
entity.Set(new Health());
entity.Has<Health>();
entity.Remove<Health>();
ref entity.Get<Health>();
entity.TryGet(out Health health); // Class components only.
TryGet works only for class components. For a struct component, the out value would be a copy, and a change to it would be lost. For a struct, use Has and ref Get.
🏷️ Aspect
Aspect is an Entity with a defined set of Components. Used to speed up the interaction with Entity.
public struct PlayerAspect : IAspect
{
public Entity Entity { get; set; }
public PlayerTag Tag => Entity.Get<PlayerTag>();
public Health Health => Entity.Get<Health>();
public Transform Transform => Entity.Get<Transform>();
public NestedAspect NestedAspect => Entity.Get<NestedAspect>();
}
PlayerAspect player = anyEntity.As<PlayerAspect>();
player.Health.Value -= 1;
player.Add(new OtherComponent());
player.Exist();
player.Kill();
🏷️ Query
Query is used to get required Entities.
-
Getting a Query
// Query of an Entity
var query = Query.Of<Health>()
.With<PlayerTag>()
.Without<DeadTag>();
// Or Query of an Aspect
var query = Query.Of<PlayerAspect>();
-
Operating with Query
// Iterate over
foreach (Entity entity in query)
{
}
// Or get Single
Entity entity = query.Single();
// Common IEnumerable methods
query.Where(entity => entity.Get<Health>().Value > 50)
.Any();
-
Fast Single Query
// Of Component
GameData data = Query.Single<GameData>();
// Or of an Aspect
PlayerAspect playerAspect = Query.Single<PlayerAspect>();
🏷️ Entity hierarchy
Entity provides few methods to combine them into a Parent-Child relationship. All Childs will be killed after a Parent death.
entity.SetParent(parentEntity);
entity.UnParent();
Unity integration
The Yogurt.Unity assembly connects entities to Unity objects. It is in the Unity folder and in the Yogurt.Unity namespace. The core Yogurt assembly does not use it.
🏷️ Wait
Wait gives conditions that you can await. A wait stops when its Life dies. A stopped wait throws OperationCanceledException.
await Wait.Until(IsPlayerOnExit, level.Life());
await Wait.While(IsStunned, zombie.Life());
await Wait.Seconds(0.5f, zombie.Life());
await Wait.Update();
A wait without a Life stops when the application quits.
🏷️ Run
Run calls an action one time in each frame. It stops when the entity dies.
projectile.Run(() => projectile.View.transform.position = projectile.Motion.Position);
🏷️ Link
Link connects a GameObject to an entity. When the entity dies, Yogurt despawns the GameObject.
Entity zombie = Entity.Create().Link(view.gameObject).Add(view);
Entity clicked = hit.collider.GetEntity();
To remove a linked GameObject, kill its entity. Do not destroy a linked GameObject.
🏷️ Asset
Asset<T> is a prefab reference. PooledAsset<T> also keeps despawned instances and spawns them again.
public class LevelConfig : ScriptableObject, IComponent
{
public PooledAsset<AgentView> Zombie;
}