Hello SunBurn community!
Yesterday we released the latest SunBurn 2.0 Game Engine update (2.0.9). It includes some awesome new features, enhancements, fixes, and more, including SunBurn's new object-level components.
Object-level Components
SunBurn’s object-level components allow you to plug custom code, behaviors, and modifiers into any entity, scene object, or light.
The system exposes a number component events as well as object events (already available in SunBurn), which can be used to write custom code that snaps into any object or light.
Events available to components:
- OnInitialize - called when the component's parent object is assigned
- OnComponentListChanged - called when other components are added / removed from the parent object
- OnMessage - called when another component issues an inter-component message
- OnUpdate - called when the parent object is updated during the game loop
- OnCollisionReact - called when the parent object collides with another object, also allows overriding default collision behavior
- OnCollisionTrigger - called when the parent object collides with another object and the parent's CollisionType is set to Trigger
SunBurn's components can also be used to add custom properties to objects and lights. This makes it possible to plug game specific information like health / damage, inventory items, and more into any object or light.
All components are automatically serialized (saved / loaded) with the parent object. Custom component properties can be serialized with the component by overriding the component's SetObjectData() / GetObjectData() methods and reading / writing the property to the provided SerializationInfo object (see below for details).
More component features:
- Strongly typed - makes it easy to see the relationship between components and the target object type
- Direct interaction - get an object's component by type using <parent object>.Components.GetComponent<type>();
- Messaging - send and receive inter-component messages and notifications
- Dependencies - SunBurn can automatically create and add dependent components when adding a component to an object (if desired)
Example components:
// Allow .net to extract serialization info.
[Serializable]
public class PlayerClassComponent : BaseComponent<ISceneEntity>
{
// Property that extends the scene object properties.
public float Strength { get { return _Strength; } set { _Strength = value; } }
private float _Strength;
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
// Save the strength to the SerializationInfo.
SerializationHelper.SerializeFieldOrEnum(ref _Strength, info, "Strength");
base.GetObjectData(info, context);
}
public override void SetObjectData(SerializationInfo info, StreamingContext context)
{
// Load the strength from the SerializationInfo.
SerializationHelper.DeserializeField(ref _Strength, info, "Strength", true);
base.SetObjectData(info, context);
}
}
// Make this component dependent on the PlayerClassComponent component.
[ComponentDependency(typeof(PlayerClassComponent))]
// Allow .net to extract serialization info.
[Serializable]
public class DoSomeThingWithStrengthComponent : BaseComponent<ISceneEntity>
{
public override void OnUpdate( GameTime gametime )
{
// Try to get the PlayerClassComponent component assigned to the scene object.
PlayerClassComponent playerclass = ParentObject.Components.GetComponent<PlayerClassComponent>(false);
if(playerclass != null)
{
// Grab the strength value.
float strength = playerclass.Strength;
// Do something awesome based on the strength!
}
base.OnUpdate(gametime);
}
}
The current release contains the complete component system, components can be created and assigned in code. However adding component using the editor is not yet implemented, but will be available soon.
Prefab Objects
This release introduces prefabs, which provide the ability to serialize an object (or hierarchy of objects) into a prefab and then create any number of object instances from that prefab. Prefabs can also be saved and used as object templates across sessions and platforms.
// Create a prefab from a scene object.
PrefabObjectGenerator prefab = new PrefabObjectGenerator(sceneobject);
// Create an object instance from the prefab.
ISceneObject obj1 = (ISceneObject)prefab.CreateObject();
// Create a second object instance from the prefab.
ISceneObject obj2 = (ISceneObject)prefab.CreateObject();
Generating prefab objects is supported on Windows, and creating object instances can be done on any platform.
And More!
Also included in the release is full Avatar support (same great features as SunBurn 1.3.2), the new SerializationHelper class, fixes, and more (see the SunBurn 2.0.9 release notes for details).
If you have any questions or comments let us know!
-John Kabus
Other SunBurn 2.0 Blogs:
Announcing the SunBurn 2.0 Game Engine - free upgrade, new editions, and updated features
SunBurn 2.0 Collisions, Scenegraph, and Components - new collision system, components, and more
SunBurn 2.0 upgrade for our Torque customers - upgrade path for all of our previous TLK technology customers
SunBurn 2.0 goes Mobile on Windows Phone 7! - full Windows Phone 7 support, light mapping, and more
Holiday, Components, and more! - read about the new components and more

Posted
12-09-2010 7:33 PM
by
JohnK "bobthecbuilder"