Retrieve Objects

Learn how to get access to any object inside your code

The Object Manager

The nero::ObjectManager class allows you to retrieve or perform certain actions on all your Game Objects. From your Scene class you can get access the Object Manager with the following method :

ObjectManager::Ptr getObjectManager();

Find Objects

Each Game Object can be assigned an Object_Name through the Engine Editor. The name you give to an Object will be the primary way to identify it. Each object also has an Object_Id created automatically by the Engine, you can find an Object using its Object_Id but that is not recommended. The Object_Id should only be used internally by the Engine.

Knowing the name of a Game Object, you can retrieve it using the code below :

Object::Ptr getObjectManager->findObject(sf::String name);

//Example 01
Object::Ptr myObject = getObjectManager()->findObject("my_object_name");

//Example 02 : Using c++11 auto
auto myObject = getObjectManager()->findObject("my_object_name");

The Object Manager provides other methods to find Objects. If you know the nature of the object you are looking for, by example if the object is a Sprite_Object or Physic_Object you can use a more specialized method to find objects.

//nero::ObjectManager Find Objects

//Generic
Object::Ptr findLayerObject(sf::String name);

//Specilized
Object::Ptr findLayerObject(sf::String name);
Object::Ptr findObjectInLayer(sf::String name, sf::String layer);
Object::Ptr findSpriteObject(sf::String name);
Object::Ptr findPhysicObject(sf::String name);
Object::Ptr findSolidObject(sf::String name);

Move Objects

Moving an object simply consists to cut the object from the Scene Graph or if you want, remove it from the Game World without destroying it. The move methods will return you the only remaining copy of the Object. You can then add the object back to the Game World at a different location.

//nero::ObjectManager Move Objects

//Generic
Object::Ptr moveObject(sf::String name);

//Specialized
Object::Ptr movePhysicObject(sf::String name);
Object::Ptr moveSpriteObject(sf::String name);
Object::Ptr moveSolidObject(sf::String name);

Remove Objects

If you want to completely destroy an object, you can do so with the methods below. You can even destroy an entire layer of objects at once. The removal methods will return a boolean, the value will be true if the removal succeeded and false if not. The removal will fail if the object does not exist or has already been destroyed.

//Object_Manager Remove Objects

bool removeObject(Object::Ptr object);
bool removeObject(sf::String name);
bool removeLayer(std::string name);

Cast Objects

As you can notice the methods Find and Move always return a generic nero::Object::Ptr whatever the type of object you try to find. If you want to access the “True” object you are retrieving you will have to convert it back to its original type. Such conversion is called a Cast or Casting an object. Each Object_Type has a static method Cast() to perform the conversion.

nero::Object::Cast(Object::Ptr object)
nero::LayerObject::Cast(Object::Ptr object)
nero::SpriteObject::Cast(Object::Ptr object)
nero::PhysicObject::Cast(Object::Ptr object)
  • Example 01 : Sprite and Physic Objects
auto my_cloud = getObjectManager()->findObject("cloud");
auto my_ground = getObjectManager()->findObject("ground");

nero::SpriteObject::Ptr sprite_object = nero::SptriteObject::Cast(my_cloud);
nero::PhysicObject::Ptr physic_object = nero::PhysicObject::Cast(my_ground);
  • Example 02 : Solid Object

A Solid Object is a Physic Object with a Sprite Object as a child, so a Solid Object is cast to a Physic Object

auto player = getObjectManager()->findSolidObject("player");

nero::PhysicObject::Ptr physic_object = nero::PhysicObject::Cast(player);
nero::SpriteObject::Ptr sprite_object = nero::SptriteObject::Cast(player->getFirstChild());

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Nero Games will use the information you provide on this form to be in touch with you and to provide updates and marketing.