SunBurn 2.0: components, perfabs, and more!

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"

Comments

CJ Bailey wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-10-2010 8:09 AM

Excellent!  This answers my question about AI controllers.  One question though... is it possible to add multiple components of the same type to a SceneObject?  e.g. if I wanted to add multiple AI controllers to an object.

"adding component using the editor is not yet implemented, but will be available soon" - any ideas how soon?  I was about to start creating a bolt-on manager for assigning AI controllers on the fly... but if you are integrating Components into the UI very soon I'll not bother.

JohnK "bobthecbuilder" wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-10-2010 6:31 PM

Hi cj,

You can only have one component of a specific type on an object.  If you need multiple values from the same type it would be better to implement the values as an array rather than add multiple of the same component (this is also more efficient).

No details on the ui just yet, but we'll definitely post some info when we're close to releasing the update. :)

Thanks!

BigDaddio wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-11-2010 2:02 AM

@Cj why would you want multiple ai components? Or at least multiples of the same component?

@John What is the component overhead if really anything?

I am used to using a number of small components as opposed to a single complex one per object. I can easily have 4 or more components on a projectile, Physics, Collision, Damage, Lifetime, etc.

CJ Bailey wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-11-2010 3:07 PM

@BigDaddio - Having multiple AI controllers per SceneObject could allow you to have, for example, one AI controller for movement and another for controlling facial expressions or something.

JohnK "bobthecbuilder" wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-13-2010 7:44 AM

Hi guys!

@BigDaddio, the overhead is very low, 4 components is no problem.

If hundreds of objects are using 20+ components I can see things getting bogged down from the overhead of calling into all the components.

@cj, but those would be different classes, so you can add them both no problem (they're two different types).  If a single class exposes both then it should really process both in a single component instance.

Let me know if this helps!

CJ Bailey wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-13-2010 9:52 AM

Thanks John.  I think I've misunderstood how the Component system works.  I was thinking you created a component and then added it to each specific entity... e.g. SceneObject.AddComponent(component);

I've not had chance to play around with it yet so my understanding is not yet developed.  I've had a re-read of your blog and think I'm beginning to get it now.... you create a single component which applies to ALL entities/objects or whatever (specified by the generic <T>).

If you get time, could you give us some hints of how Components would fit within the editor and a rough idea of how long we may have to wait for this feature?

It may be that my AI controllers need a slightly different solution since I want to be able to assign specific AI controllers to specific entities... not an entity type.

JohnK "bobthecbuilder" wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-13-2010 4:42 PM

Hi cj:

"I was thinking you created a component and then added it to each specific entity... e.g. SceneObject.AddComponent(component);"

That's how it works, and you can add as many components as you want to the object / entity.

However if you add a second component of the same type / class it will replace the first.

As an example if I add a SpinComponent to the object, then add a BounceComponent, the object will have two components (spin and bounce - as they're two different types / classes):

SpinComponent spin = new SpinComponent();

BounceComponent bounce = new BounceComponent();

sceneobject.Components.Add(spin);

sceneobject.Components.Add(bounce);

However if I try to add another SpinComponent it will simply replace the first and the object will still have two components.

Let me know if this helps!

CJ Bailey wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-13-2010 5:28 PM

Errr... ok... so it does work how I originally thought!  D'oh!  I need to have a play to get to grips with it and try out my AI controller concept.

Unfortunately (paid) work keeps getting in the way of my fun time!

BigDaddio wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-14-2010 5:09 PM

@cj I think we are saying the same thing, I have a number of components that deal with AI and by stacking them I get more complex behaviors. I make pretty simple components though. Like one that just makes the object turn towards a target object. It has a few exposed elements, like rotate speed, the target.

Now I am wondering if we will be able to attach these components and edit the exposed values via the editor. Part of our workflow is I write the component, then hand it off to my son who is my co-conspirator. He will then tweak the values in the editor. Well that's how it worked with Torque and Unity.

JohnK "bobthecbuilder" wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-15-2010 1:16 AM

Hi guys!

The components can definitely be stacked as long as they are of different C# classes / types.

As mentioned in the blog adding / editing via the editor will be available soon. :)

That update also allows editing arbitrary object types, meaning you can add ANY object that exposes ISceneEntity and edit its properties in-editor. ;)

Awesome stuff on the way!

Dean Wadsworth wrote re: SunBurn 2.0: components, perfabs, and more!
on 12-15-2010 11:34 AM

This is great! :) and prefabs! :D

Question, I have scenes that use a lot of textures. Is there away in the editor to group textures like lights? or group them by objects? or any future plans for something like this? :D

Thx

JohnK Blog wrote SunBurn Game Engine: Transparencies, Player Controller, and More!
on 08-17-2011 1:15 AM

Hello SunBurn community! If you follow my blogs you know we’re adding a number of unannounced features

JohnK Blog wrote SunBurn Launches Powerful new Community Plugin System
on 10-16-2011 3:16 PM

Hello SunBurn community! Last night we rolled out a development preview of the SunBurn Game Engine’s

JohnK Blog wrote New SunBurn Community Resources Portal!
on 11-01-2011 5:45 PM

Hello SunBurn community! Two weeks ago we rolled out a powerful new resource system for the SunBurn Game

JohnK Blog wrote SunBurn Game Engine: A Whole New Level of Flexibility!
on 11-16-2011 5:06 PM

Hello SunBurn community! Today we’re announcing the last couple of features in the upcoming SunBurn

JohnK Blog wrote Orbitron: Revolution blasts onto Xbox LIVE Marketplace!
on 12-05-2011 9:52 PM

Hello SunBurn community! Talk about an exciting weekend! The awesome team at Firebase Industries just

JohnK Blog wrote SunBurn 2.0.17 Released – Advanced Lighting, Transparencies, and tons of Enhancements!
on 12-09-2011 4:45 PM

Hello SunBurn community! It’s here! Today we released the SunBurn Game Engine 2.0.17 update –

JohnK Blog wrote New SunBurn Documentation and Silverlight WP7 Example!
on 12-12-2011 9:09 PM

Hello SunBurn community! We’ve just updated the SunBurn Getting Started documentation to ensure

JohnK Blog wrote Starting 2012 with style: SunBurn Game Engine 2.0.18 Preview!
on 01-27-2012 2:01 PM

Hello SunBurn community! We're kicking the year off with a huge new update to the SunBurn Game Engine

JohnK Blog wrote SunBurn Game Engine 2.0.18: Built-in Character Controller!
on 02-04-2012 4:50 PM

Hello SunBurn community! Last night we delivered a feature-complete preview of SunBurn Game Engine 2

JohnK Blog wrote SunBurn 2.0.18 Released - Physics, Char Controller, More!
on 02-14-2012 3:46 PM

Hello SunBurn community! This morning we launched the much anticipated SunBurn Game Engine 2.0.18! The

JohnK Blog wrote New sgMotion Plugin and the SunBurn 2.0.18 Refresh!
on 02-23-2012 4:49 PM

Hello SunBurn community! We just rolled out two exciting new updates for the SunBurn Game Engine ! The

maconbot wrote re: SunBurn 2.0: components, perfabs, and more!
on 04-30-2012 4:29 PM

I can't find what:

[CODE]public override void SetObjectData(SerializationInfo info, StreamingContext context)[/CODE]...what is SerializationInfo and StreamingContext using?  I've tried several of XNA's .NET to no avail.  Thanks!

maconbot wrote re: SunBurn 2.0: components, perfabs, and more!
on 04-30-2012 4:43 PM

using System.Runtime.Serialization;



Please login to post comments.