Jump to content

How to retrieve ALL components?


photo

Recommended Posts

Hi, is there a easy or preferred way to retrieve all components or all node with a type of component? Even if this is slow.

The alternative would be to store all components at creation time, but there may already exist an easier way to do that?

Link to comment

Hello! 

template <class T>
void collectAllComponents(Unigine::Vector<T *> &out_components)
{
	Unigine::Vector<Unigine::NodePtr> root_nodes;
	Unigine::World::getRootNodes(root_nodes);
	for (auto & it : root_nodes)
		Unigine::ComponentSystem::get()->getComponentsInChildren<T>(it, out_components, false);
}

// usage example
Unigine::Vector<MyComponent *> components;
collectAllComponents(components);

 

  • Like 1
Link to comment
×
×
  • Create New...