Rookboom

Hi

I have been working on a Level Editor and have run into some problems with serializing my scene graph. Sticking with the game component idea for the moment, all the objects in my scenegraph are currently DrawableGameComponents.

Using the nifty XmlSerializer class I can easily store my scene graph with all its children and load it at a later time. However, this requires every class being serialized to have an parameterless contructor and all GameComponents requires the Game as a parameter.

The Game Property of GameComponent is unfortunately a readonly property and cannot be set after serialization. This causes problems since my game objects relies on services provided by the game.

Any ideas will be appreciated.

Thanks
Johan


Re: XNA Framework Game Component Serialization

Jim Perry

Do the objects have to inherit from DrawableGameComponent This is probably only useful if you're adding the objects to the game's component list. You can probably just add the Update and Draw methods and reference to the game object to the object classes yourself and call them from the scene graph.




Re: XNA Framework Game Component Serialization

Darkside

Probably best not to serialise the game coponent class it'self, rarther create a seperate clone class with out the game component mess and use that for serialisation and have the load method update the game component.

Does this make sense

Darkside (mumbling nonsence for years now)






Re: XNA Framework Game Component Serialization

Jim Perry

That's what I was going for. I think I just worded it badly.




Re: XNA Framework Game Component Serialization

Darkside

S'all right Jim we all have these bouts of madness from time to time.

Only recently through the SpaceWar starter kit and it's Setting.CS, that i found the proper way to do it, all my previous attempts at serialisation failed misserably.

Darkside






Re: XNA Framework Game Component Serialization

Jim Perry

Serialization is just so easy in .NET I'm tempted to always use it instead of doing IO myself.




Re: XNA Framework Game Component Serialization

Darkside

Yeah, once you've got it figured out it's dead easy, although the Help doesn't really help.

I wish I'd know how to use it properly before I made Hack-1for the Xbox360Homebrew contest, took me quite a while to write my own XML read and write code, twas a pain.

Now with serialisation all it takes is a couple of lines, damn.

Darkside






Re: XNA Framework Game Component Serialization

Rookboom

Thanks guys, I wanted my game actors to be drawable game components. I like the idea of my game components being loaded and disposed by the framework and drawn at the appropriate time. The idea seems good but I have not seen many concrete examples of DrawableGameComponents. Even the SpaceWar example do not make use of them. Which makes me wonder why it is part of the framework if a simple game cannot make good use of it.

The whole game component concept is one of the things that sparked my interest in XNA. If everyone developed components using the same interface, the XNA development community can really easily share their components. Alternatively, if everyone go about and use their own interface for writing game objects, code reuse becomes more difficult.

Thanks for your comments.

Johan




Re: XNA Framework Game Component Serialization

Jim Perry

I think people just need some time to learn the best uses for components. Also, the XNA team might make changes to it to make it more useful in the next version, who knows.




Re: XNA Framework Game Component Serialization

Mitch Walker - MSFT

You don't need to derive from DrawableGameComponent (or GameComponent). You could implement IGameComponent, IUpdateable and/or IDrawable yourself. This would still allow you to plug into Game's Components collection. You'd just have to implement some of the nice functionality the default classes provide.