Access rendering::Scene through world plugin
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();
if(!scene)
{
gzerr << "(MyPlugin) rendering::RenderEngine::Instance()->GetScene() returned NULL.\n";
}
else
{
gzmsg << "(MyPlugin) Scene loaded.... \n";
}
// try alternative access
scene = rendering::get_scene(this->world->GetName());
if(!scene)
{
gzerr << "(MyPlugin) rendering::get_scene() returned NULL.\n";
return;
}
else
{
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.cc:221] (MyPlugin) rendering::RenderEngine::Instance()->GetScene() returned NULL.
Error [MyPlugin.cc:231] (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!
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.
Any luck with this?