You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tools for an easier usage of RelEcs with the Godot Engine.
// a pure ecs componentclassHealth{publicintValue;}// For the extra godot functionality, inherit from GDSystempublicclassExampleSystem:GDSystem{// Godot ScenePackedSceneSomeScene= GD.Load<PackedScene>("res://SomeScene.tscn");publicoverridevoidRun(){// Let's say our Scene looks like this://// SomeScene (SomeScene : Node2D)// -- Sprite (Sprite : Node2D)// // creating an instance of SomeScene.tscn and adding it to the scene tree.varnode= SomeScene.Instance<SomeScene>();
AddChild(node);// RelEcsGodot adds a method overload for Spawn, that allows to take a Node type object// RelEcsGodot will automatically convert that Node into an Entity with Components in the ECS.Entityentity= Spawn(node).Id();// this is now a normal ecs entity and we can do the things we're used to// like adding other struct components to it.
On(entity).Add(new Health {Value=10})// despawns the entity AND frees the node it was created from.
DespawnAndFree(entity);// NOTE: just calling Despawn(entity) will not free the node, only the entity.// We can query for those Nodes like so:foreach(var(entity, sprite, health)inQuery<SomeScene,Sprite,Health>()){// do something with your nodes here}// entities that are spawned from a node also have a special component that you can query for.varquery=Query<Root>();}}