Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Changing static component at runtime does not result in change in physics

Good morning, everyone, I am trying to change the <static> component of a box at runtime with a plugin.

I am using gz-sim garden and I initially generate my world with objects with <static>True</static> in the SDF file. I would like to change this value for one object at the time. I have the BoxModelEntity, and I can access to its components.

I have done it this way, but although from the component inspector I can see the flag change, the object remains immovable and the collisions are not as I would expect, i.e. the box behaves as if it has infinite mass.

boxModelEntity = _ecm.EntityByComponents(components::Model(), components::Name(boxModelName));

if (_ecm.Component<components::Static>(boxModelEntity)->Data())
  gzdbg << "The box model is static" << std::endl;

  // Set the static component of the boxModelEntity to false
  _ecm.CreateComponent(boxModelEntity, components::Static(false));

  // warn the user that the static component of the boxModelEntity has been set to false
  gzdbg << "The static component of the boxModelEntity has been set to false." << std::endl;

  // Update the physics engine  to apply the changes  to the boxModelEntity (set the static component to false) 
  _ecm.SetChanged(boxModelEntity, components::Static::typeId, ComponentState::OneTimeChange);
  gzdbg << "The box model is not static" << std::endl;

It seems that once the object is generated in static, despite the change in that property, relative physics is not activated (I need gravity).

Another solution seemed to me to delete the box and recreate an identical one in the same pose with the static component set to false, but I still cannot find an easy way to generate the same box at runtime after removing the previous Entity.

Do you have any suggestions? Thanks!