<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Adding &#x2F; Removing Schema fields during runtime]]></title><description><![CDATA[<p>Hi,</p>
<p>I am working on a opensource ecs game engine and I wanted to replace the current custom network management with Colyseus !</p>
<p>But, ECS means that my game is composed by several <code>Entity</code> that can have 0 to many components. A <code>Component</code> is assigned to an <code>Entity</code> by putting him into a <code>Entity.components</code> object holding them by their names.</p>
<p>I am not very familiar with the Schema aspect, how can I bring this data structure into Colyseus ?</p>
<p><strong>Idea 1 :</strong></p>
<p>Define types during runtime with <code>defineTypes</code>, something like :</p>
<pre><code>const entity = new Entity() // Entity extends empty Schema
entity.addComponent(new MyComponent()) // MyComponent extends Schema with data structure

// The second line will run this :
schema.defineTypes(entity , {
  MyComponent: MyComponent
});
</code></pre>
<p>But, well ... Schema defines types in object prototype (<a href="https://github.com/colyseus/schema/blob/master/src/annotations.ts#L283" rel="nofollow">https://github.com/colyseus/schema/blob/master/src/annotations.ts#L283</a>) not instance ... so it will not work as each <code>Entity</code> instance may have different <code>Components</code>.</p>
<p><strong>Idea 2 :</strong></p>
<p>Sending maps of <code>Components</code> for each <code>Entity</code> (preferred solution as I already have a <code>Entity.components</code> attributes.</p>
<pre><code>class Entity extends Schema {
    @type({ map: Components})
    components = new MapSchema&lt;Components&gt;();
}
</code></pre>
<p>But again I think it will not work because the engine will store different <code>Component</code> data structures. Examples : <code>PositionnableComponent</code> with <code>x</code>, <code>y</code>, <code>angle</code>, <code>HealthComponent</code> with <code>current</code>, <code>maximum</code>, etc ...</p>
]]></description><link>http://discuss.colyseus.io/topic/371/adding-removing-schema-fields-during-runtime</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 17:13:44 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/371.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 May 2020 10:56:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Adding &#x2F; Removing Schema fields during runtime on Invalid Date]]></title><description><![CDATA[<p>Hi,</p>
<p>I am working on a opensource ecs game engine and I wanted to replace the current custom network management with Colyseus !</p>
<p>But, ECS means that my game is composed by several <code>Entity</code> that can have 0 to many components. A <code>Component</code> is assigned to an <code>Entity</code> by putting him into a <code>Entity.components</code> object holding them by their names.</p>
<p>I am not very familiar with the Schema aspect, how can I bring this data structure into Colyseus ?</p>
<p><strong>Idea 1 :</strong></p>
<p>Define types during runtime with <code>defineTypes</code>, something like :</p>
<pre><code>const entity = new Entity() // Entity extends empty Schema
entity.addComponent(new MyComponent()) // MyComponent extends Schema with data structure

// The second line will run this :
schema.defineTypes(entity , {
  MyComponent: MyComponent
});
</code></pre>
<p>But, well ... Schema defines types in object prototype (<a href="https://github.com/colyseus/schema/blob/master/src/annotations.ts#L283" rel="nofollow">https://github.com/colyseus/schema/blob/master/src/annotations.ts#L283</a>) not instance ... so it will not work as each <code>Entity</code> instance may have different <code>Components</code>.</p>
<p><strong>Idea 2 :</strong></p>
<p>Sending maps of <code>Components</code> for each <code>Entity</code> (preferred solution as I already have a <code>Entity.components</code> attributes.</p>
<pre><code>class Entity extends Schema {
    @type({ map: Components})
    components = new MapSchema&lt;Components&gt;();
}
</code></pre>
<p>But again I think it will not work because the engine will store different <code>Component</code> data structures. Examples : <code>PositionnableComponent</code> with <code>x</code>, <code>y</code>, <code>angle</code>, <code>HealthComponent</code> with <code>current</code>, <code>maximum</code>, etc ...</p>
]]></description><link>http://discuss.colyseus.io/post/1218</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1218</guid><dc:creator><![CDATA[SauceCodeFr]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Adding &#x2F; Removing Schema fields during runtime on Invalid Date]]></title><description><![CDATA[<p>Okay I am working on something !</p>
<p>The solution may be having a global hashmap of <code>Component</code> detached from <code>Entity</code> objects. It allows us to group the <code>Component</code> types in the State and send them as group. Not sure it will works but, at least i will try this :)</p>
<p>I will keep updated the work on this thread.</p>
]]></description><link>http://discuss.colyseus.io/post/1220</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1220</guid><dc:creator><![CDATA[SauceCodeFr]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Adding &#x2F; Removing Schema fields during runtime on Invalid Date]]></title><description><![CDATA[<p>Did it work?</p>
]]></description><link>http://discuss.colyseus.io/post/1257</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1257</guid><dc:creator><![CDATA[virtumonde]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>