Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:25:55+00:00 2026-06-07T09:25:55+00:00

My entity system for my game uses templates to lay out how entities are

  • 0

My entity system for my game uses templates to lay out how entities are created. Something like:

EntityTemplateManager.register("zombie",
    new PhysicsComponent(10), // speed
    new SpriteComponent("zombie"), // graphic
    new HealthComponent(100) // health
);

I like this part of the system because it makes sure I don’t miss any parameters or screw up their type.

Then I can create a new entity like this:

entity : Entity = EntityTemplateManager.create("zombie");

Pretty straight forward.

What I do now, to actually create the entity, is have the EntityTemplateManager create 1 entity to use as a default, then I call clone() on the entity and it goes through and clone()s all of its components and returns the result.

Actual code:

public function clone() : Entity
{
    var components : Vector.<Component> = new Vector.<Component>();

    var length : int = _components.length;

    for (var i : int = 0; i < length; ++i)
        components.push(_components[i].clone()); // copy my local components to the new entity

    return new Entity(_name, _type, components);
}

The problem is, every time I create (design) a new component, I have to write (design) a clone() method inside of it AND keep track of all the parameters that were called on the constructor to create a brand new, default stated component.

So I end up with junk like this:

public class ComponentX
{
    protected var _defaultName : String;
    protected var _defaultStartingAnimation : String;
    protected var _defaultBroadcastAnimationEnded : Boolean;
    protected var _defaultOffsetX : Number;
    protected var _defaultOffsetY : Number;

    // other stuff hidden

    public function ComponentX(name : String, startingAnimation : String, broadcastAnimationEnded : Boolean = false, offsetX : Number = 0, offsetY : Number = 0) : void
    {
        super();

        _defaultName = name;
        _defaultStartingAnimation = startingAnimation;
        _defaultBroadcastAnimationEnded = broadcastAnimationEnded;
        _defaultOffsetX = offsetX;
        _defaultOffsetY = offsetY;
    }

    public function clone() : Component
    {
        return new ComponentX(_defaultName, _defaultStartingAnimation, _defaultBroadcastAnimationEnded, _defaultOffsetX, _defaultOffsetY);
    }

    // other methods
}

I really don’t like this — it’s wasteful and error prone.

How could I best store the parameters of the EntityTemplateManager.register() function (including the components’ constructors parameters) and use that new storage to create entities from instead?

I’ve tried some generic clone() methods like with a ByteArray or describeType(), but they don’t work with protected / private variables.

Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:25:58+00:00Added an answer on June 7, 2026 at 9:25 am

    Few months ago I wrote my own Entity-Component manager too. I’ve done something like this (in your case):

    EntityTemplateManager.register("zombie", [
        {type: PhysicsComponent, attr: {speed: 10}},
        {type: SpriteComponent, attr: {graphic: "zombie"}},
        {type: HealthComponent, attr: {health: 100}}
    ]);
    

    Registering a new template works as below:

    private static var definitions:Dictionary = new Dictionary();
    
    public static function register(templateName:String, componentDefinitions:Array):void
    {
        definitions[templateName] = componentDefinitions;
    }
    

    The create function retrieves the specified component template and create components like this:

    var components:Vector.<Component> = new Vector.<Component>();
    
    // Create all components
    for each (var definition:Object in componentDefinitions) {
        var componentClass:Class = definition.type;
        var component:Component = new componentClass();
    
        // Set default parameters
        for (var prop:String in definition.attr) {
            component[prop] = definition.attr[prop];
        }
    
        components.push(component);
    }
    
    // Then create the entity and attach the freshly created components.
    // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to write an Artemis like game component/entity system in C++. I
Our system uses an Entity Framework based data layer. For the recent months, we've
I'm making a component based entity system for a game engine. I have an
I'd like to know if Entity Framework System.Data.Entity.DbContext gets configured each time it's instantiated.
I'm building a new entity system in Java. I'm wondering whether my proposed method
I'm building an Entity System for a game, and basically I'm not sure whether
I'm considering porting the java library Artemis . An entity system framework. I havn't
I have this error message could not load assembly 'system.data.entity, version 4.2.0.0, culture=neutral,publickeytoken=b77a5c561934e089' or
How to add a FunctionImportMapping programmatically using classes from the System.Data.Entity.Design namespace? This blog
This code using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using System.Data.Entity.ModelConfiguration;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.