I’ve written a small StateManager, deriving from Object, and a baseclass for GameStates, deriving from Component.
That all works fine, I then tried experimenting with serializing component properties (aka Attributes) to disk.
Following the docs as best I could understand them, I have some code in a derived GameState class that looks like this:
public:
float myValue=666.0f;
static void RegisterObject(Context* context){
context->RegisterFactory<GameMainMenuState>();
URHO3D_ATTRIBUTE("My Value",float,myValue,666.0f,AM_DEFAULT);
}
Later, I attempt to serialize the entire scene to an XML file as follows:
Urho3D::File serializer(context_, “testscene.xml”, FILE_WRITE);
GetNode()->GetScene()->SaveXML(serializer);
I should mention that I am manually calling the static method to register factory and attribute early in the application startup code.
The problem is that during serialization, my custom attribute is never written to disk: the built-in attributes are showing up for Nodes, but not for any Component, including my custom component.
What am I doing wrong? I assume that since Component derives from Serializable, and can hold Attributes, that these would be Serialized too.
PS - I just checked, I can successfully query the attribute variant using GetAttribute, and I can also successfully query the Context directly for the same. So my attribute is definitely registered with the Context, it’s just failing to be Serialized, despite having AM_DEFAULT mode.
The only thing that appears to be different about my implementation with respect to the Samples is that my Component is a Derived class (correctly registered as such, and playing well with Urho in every other respect, including custom events). GameStateX derives from IGameState, which in turn derives from Component… with this arrangement, Serialization appears to be failing!