Special thanks
Before I start talking about archetypes, I wish to thank Jeremy Stieglitz from Trendy Entertainment for further explaining to me why I should be using archetypes.
Introduction
Archetypes are similar to Prefabs in that we use them to create instances of an object. The nice thing about using instances is that when you change the archetype that is stored within the package, it will update all instances in a map. On top of that, if you change the instance of an archetype then the value remains and it won’t be updated.
For those of you who come from an Unreal Engine 2 or Unreal Engine 1 background, archetypes is almost equivalent to creating many subclasses of a parent class and altering the class’s default properties. I say that it’s almost equivalent because while it does a somewhat similar job, it isn’t as easy to use as archetypes.
So now that we know what they are, you may wonder how they’re useful to your project. Here are some cases where they do become very useful.
- When many variations of an object or actor is required (common examples are inventory variants of the same type)
- When in editor tweaking would be easier, or if the programmer is implementing options that are outside of his or her responsibility (common examples would be allows colour options)
- Reduce load time and or compile time (if you reference any content through script Unreal Engine 3 will load the content both in game and during compilation)
When many variations of an object or actor is required
It is usually common practise in programming to group things together based on the common functionality. For example, weaponry in Unreal is usually sub classed from Weapon. Inventory items in Unreal is usually sub classed from Inventory.
Back in Unreal Engine 2 or 1 we would add in the differences through subclasses. That is to say a Flak Cannon would be a subclass of Weapon, and that subclass would contain the differences that make the Weapon into a Flak Cannon.
When the differences are data or content driven then using archetypes is usually the best solution (I am sure that there will be some edge cases where using archetypes isn’t a good idea). So a good example of this, is when you have variations of something; let’s say five variations of the shock rifle where each one has a different material and different weapon damages. Archetyping the shock rifle would be the best solution here.
Using archetypes in code is simple. When spawning, you insert the archetype reference in the spawn function (for example, Spawn(class’Actor’, SpawnOwner, SpawnTag, SpawnLocation, SpawnRotation, ArchetypeReference, bNoCollisionFail). When creating an object, you insert the archetype reference in brackets after the class declaration (for example, new () class’Object’(ObjectArchetype)).
When in editor tweaking would be easier, or if the programmer is implementing options that are outside of his or her responsibility
Often when I’m told to implement a feature without the required content available, I’m often told to put in a place holder art. This is because the man hours it takes for a programmer to program a quick prototype the feature is often much less than the man hours it will take for artists to create the content (especially in this day and age!).
However, during the prototyping phase lots of tweaks may be required to know whether the prototype is actually a success or not. Often, a lot of these tweaks are for things that are outside the programmers realm of responsibility (it is often the game designers responsibility). Having to constantly tweak these values inside code and recompiling is tedious and a waste of time.
It’s far quicker to open up Unreal Editor, open the test level, open up the archetype properties, play in the view port and tweak from there.
Reduce load time and or compile time
One of the things that annoys me a little bit is that compilation times have gone up when using Unreal Engine 3. From memory, I don’t think Unreal Engine 2 bothers loading anything until it’s actually needed. However, it’s a double edged sword we’re having to deal with here. (Some of this information is hear say and a little bit of logic extending… so hopefully I’m right about this information!)
In the case of Unreal Engine 2, while it’s great that it doesn’t load anything till its needed; it also causes lots of pauses and hitches during game play. In the case of Unreal Engine 3, while it’s great that nothing really pauses and hitches during game play; it can take ages to compile code if you reference too much content.
One way around it was to use dynamic load object to force loading of an object during run time without having to pay the compilation penalty. But this is quite brittle and there’s no reference checking available either.
If you’re needing to keep reference of a lot of content, and then load it in one go, what you can do is to store all of that in an object archetype and load the archetype when you need to load all the other content as well. Make sure you don’t reference the archetype in code, or it will also slow down the compilation times as well.
You also get the chance to be able to seamlessly load things in by making the archetype as an actor archetype, putting content references in there and then seamlessly travelling to that level.
Conclusion
Well, I hope that makes it clearer as to why you may want to use archetypes. They’re a really useful tool that can help resolve many issues with game development and also help to speed up development as well. They can be a bit annoying sometimes, as you sometimes have to remember if you’re reading from a saved archetype that exists in a package, or if you’re reading from an instanced archetype. But overall, they’re very, very, very useful.



