Search code examples
roboticswebots

Webots - BoundingObject of Robot becomes null after world reload (how to prevent that?)


I've a Robot node with children = [SolidCylinderJoint]. SolidCylinderJoint is a proto that I created, which defines a DEF node as a field, i.e.,

field SFNode geometry DEF BODY Cylinder {
                height 0.1
                radius 0.05
            }

Now I USE the BODY DEF node as the boundingObject of the robot, like this:

enter image description here

Now, this works great, but as soon as I hit "Reload World" or restart webots, the boundingObject becomes NULL again. I think this is happening because the robot node is loaded before the Proto, and at the time it's trying to set the boundingObject to BODY, it doesn't find that definition and hence defaults to NULL.

World file: https://pastecode.xyz/view/fab1533d

Proto file: https://pastecode.xyz/view/f558d13c


Solution

  • First, there is an issue in your PROTO, you are not allowed to make an IS in the default argument of the fields (i.e. baseColor IS baseColor):

    field SFVec3f baseColor 0.985946 0 0.0481575
    field SFNode appearance PBRAppearance { baseColor IS baseColor metalness 0.3 }
    

    About the issue with the DEF-USE, this is indeed a bug, it seems default argument of the PROTO are created after the root node and therefore not found at the creation of the root node. I have reported this here and hopefully it will be fixed in the next version of Webots: https://github.com/cyberbotics/webots/issues/1231