Archive 17/01/2023.

Help with tracking components after serialization/deserialization

Alex-Doc

I’m making a Component which relies on Component IDs for functioning, serialization and deserialization.
I’ve just noticed that some IDs are duplicated along the scene, making the whole ID system unreliable for me, as the Scene does not seems to provide recursion in GetComponent().

I know I could manually check the double IDs and eventually use a free ID, but I’d prefer if there’s another way to track down a component when serializing/deserializing.

Is there something I’m missing?

Eugene

Components must not have duplicate IDs.
Can you share minimal sample with reproducible problem?

Alex-Doc

Sorry, my fault, after further investigation I found out that the problem is the ID will change when I instantiate the xml containing the component, so my way of retrieving the component will not work.

I have to figure out something better.

cadaver

Check what the SceneResolver class does when an xml is instantiated. If your ID’s are attributes that have been annotated with AM_NODEID or AM_COMPONENTID, they should get rewritten. Though if your usecase is complex I don’t guarantee it will work out of the box.

Alex-Doc

Thanks, I’m now trying with a different approach, based on node names as I could iterate through the children of the node.

However I’m facing a weird issue, I have probably overlooked something, but it seems the Node cannot find an existing child when loading:

void PODAnimationController::SetAnimationControllersAttr( const VariantVector& value )
{
   animationControllers_.Clear();
   for( unsigned i = 0; i < value.Size(); i++ )
   {
      Node* node = node_->GetChild( value[i].GetString() , true );
      if( node )
      {
         AnimationController* controller = node->GetComponent<AnimationController>();
         if( controller )
            animationControllers_.Push( controller );
         else
            URHO3D_LOGERROR( "PODAnimationController::SetAnimationControllersAttr: value is not AnimationController type!" );
      }
      else
      {
         URHO3D_LOGERROR( "PODAnimationController::SetAnimationControllersAttr: Node \"" + value[i].GetString() + "\" not found in children of \"" + node_->GetName() + "\"!" );
         continue;
      }
   }
}
void PODAnimationController::RegisterObject( Context* context )
{
   context->RegisterFactory<PODAnimationController>();

   URHO3D_MIXED_ACCESSOR_ATTRIBUTE( "AnimationControllers", GetAnimationControllersAttr, SetAnimationControllersAttr, VariantVector, Variant::emptyVariantVector, AM_DEFAULT  );
}

While it’s able to find it through AngelScript:

Any help is welcome.

EDIT:

I’ve just found that node_->GetChildren().Size(); returns 0, considering this, where am I supposed to load my data while making sure that the children are already in there?

EDIT 1:

Solved: I just needed to assign the child names in the above function to a Vector<String> and move the children related part to ApplyAttributes().