Gazebo | Ignition | Community
Ask Your Question

Access rendering::Scene through world plugin

asked 2016-03-19 03:24:51 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi Guys,

i want to access the scene data structure within my world plugin. I found the Issue #1076 where someone tried something similar. Due to the comments i do not try to access the structure in the plugin initialization phase, but everytime the plugin is updated. Therefore in the Load function, a callback is registered by:

 void MyPlugin::Load(physics::WorldPtr _parent, sdf::ElementPtr _sdf)
 // [...]
 // register UpdateBegin Callback
 this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&MyPlugin::OnUpdate, this,_1));
 // [...]

The Callback function is defined as followed:

void MyPlugin::OnUpdate(const common::UpdateInfo &_info)
 rendering::ScenePtr scene = rendering::RenderEngine::Instance()->GetScene();
   gzerr << "(MyPlugin) rendering::RenderEngine::Instance()->GetScene() returned NULL.\n";
  gzmsg << "(MyPlugin) Scene loaded.... \n";
// try alternative access
scene = rendering::get_scene(this->world->GetName());
  gzerr << "(MyPlugin) rendering::get_scene() returned NULL.\n";
   gzmsg << "(MyPlugin) Scene loaded.... \n";


I tried this approach with Gazebo 2.2.3 as well as with Gazeb 6.5.1 and obtain both times the following output, indicating that always a nullptr is returned:

Error [] (MyPlugin) rendering::RenderEngine::Instance()->GetScene() returned NULL.
Error [] (MyPlugin) rendering::get_scene() returned NULL.

I assume that it is caused by the fact, that MyPlugin is of type WorldPlugin. I use the same approach in another SensorPlugin, where it works without any problems.

Is there any alternative in order to access it within a WorldPlugin?

With best regards!

edit retag flag offensive close merge delete


Hello, I'm having this exact problem right now. Have you figured out a method for this? You said it worked for a sensor plugin, but I need it to change the color of a light, so I don't have a sensor and thus need to use a world plugin.

sarvesh0303 gravatar imagesarvesh0303 ( 2016-06-24 02:27:49 -0600 )edit

Any luck with this?

plusk01 gravatar imageplusk01 ( 2018-02-06 12:19:36 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-02-06 12:37:43 -0600

chapulina gravatar image

A rendering scene won't be created in gzserver unless there is a rendering sensor present, such as a camera.

If you're trying to access gzclient's scene, then you'll need a plugin which runs in the client process, like a Visual or GUI plugin.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools



Asked: 2016-03-19 03:24:51 -0600

Seen: 708 times

Last updated: Feb 06 '18