Entity Factory - Material and Model assignment

Hello. Suppose I was making a game like scrabble which has 26 game pieces, each one a different letter (A, B…). Instead of making 26 entities I could make one template and then clone it and assign a material. I also have 3 different models to differentiate some letters that fall in to some groups (lets say based on score). In terms of performance, what is the best strategy here when using a factory to clone entities?

If I had a factory method such as


var entity = LetterTemplate.clone();
var letterScript = entity.script.letter;
switch(letter){
      case "A":
         letterScript.setLetter("A");
         // I could set the model based on the 3 attached model assets
         entity.model.model = letterScript.modelLowScore.resource;
        // And then set the material based on 26 material assets (although this doesn't work)...
       entity.model.materialAsset = letterScript.materialA.resource;
}

I could set each model based on the “Letter” script which has 3assets of type “model” - one for each letter, and set the material based on the 26 attached material assets. My question is every time I clone this template entity, which already has 26 materials and 3 models, am I taking a huge performance hit, or is everything really just by reference?

Currently I actually made 26 templates for each letter and clone those, but it’s obviously a nightmare to do modifications on all 26.

Any help appreciated.

Hmm. It seems like after you clone an entity and return it, you can’t change the model until it’s parented somewhere? I also only seem to be able to access 1 attribute from it which is a type:string and array:true. Everything else that I’ve added as attributes is undefined…

Well I spent the whole day converting 26 entities into one entity with 3 models and 26 textures. Happy to say it seems to be just as fast to spawn 20-30 of these by applying the model and texture in a factory method as it did to clone them from static entities already in the game. The biggest thing to realize was that you must attach an entity to the world before you can access its scripts.