Check Objects

Make sure your objects exist before the game starts

Why Check Objects

Any Game Object can be retrieved at any moment using the Object Manager Find methods. The thing to know is that the Object Manager returns a Null Pointer when it does not found an object. The reason an object is not found can be because the object simply does not exist, maybe you misspelled its name or you simply forget to assign it a name through the Engine Editor. So in general, you should test any returned object before to use it like shown below :

auto my_object = getObjectManager()->findObject(ObjectPool.my_object);
if(my_object)
{
    //do something
}

The Method CheckSceneObject()

Checking that objects exist is important specialy before you start initializing your game through the method init(). This is wy the Engine provides a special method call CheckSceneObject() to perform that task. As you may saw in the tutorial Scene Life Cycle, this method is called before the method init().

Inside that method you have to manually call the Object Manager method checkWorldObject() with the list of objects to check. The method checkWorldObject() will throw an Exception and stop the Game immediately if an Game Object cannot be found.

Checking Scene Objects is useful during the development of your Game, once the Game is ready to be released you can disable or remove the method.

//Object Manager - Check Scene Object
void checkWorldObject(std::vector<sf::String> objectNameTab);                          
void MyScene::checkSceneObject()
{
    getObjectManager()->checkWorldObject(
    {
        //list of objects name here, example : "player", "enemy_01", "treasure"
    });
}
  • Example
void MyScene::checkSceneObject()
{
    getObjectManager()->checkWorldObject(
    {
        ObjectPool.player, ObjectPool.enemy_01, ObjectPool.treasure
    });
}

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.