diff --git a/src/supertux/game_object_manager.hpp b/src/supertux/game_object_manager.hpp index 4fcd6f775a4..016913fc342 100644 --- a/src/supertux/game_object_manager.hpp +++ b/src/supertux/game_object_manager.hpp @@ -116,10 +116,11 @@ class GameObjectManager template T& get_singleton_by_type() const { - const auto& range = get_objects_by_type(); - assert(range.begin() != range.end()); - assert(range.begin()->is_singleton()); - return *range.begin(); + const auto& objs = get_objects_by_type_index(typeid(T)); + assert(objs.size() == 1); + T* obj = dynamic_cast(objs[0]); + assert(obj); + return *obj; } template