Smart pointers and simple object management system

I am attempting to implement smart pointers to create a fast but relatively bulletproof object management system that allows adding, removing and retrieving objects. I come from a C# background and am trying to wrap my head around the best way to do this regarding ownership. Code:

main.cpp:

std::unique_ptr<scene> main_scene; std::shared_ptr<game_object> obj;  int main() {     main_scene = std::make_unique<scene>(WIDTH, HEIGHT);      obj = std::make_shared<game_object>("obj", glm::vec3(0, 0, 0), glm::vec3(-90, 0, -90), glm::vec3(1, 1, 1));      main_scene->add_object(obj);      main_scene->remove_object(obj);      return 0; } 

scene.cpp:

std::set<std::shared_ptr<game_object>> game_objects;  void scene::add_object(std::shared_ptr<game_object> ptr) {     game_objects.insert(ptr); }  void scene::remove_object(std::shared_ptr<game_object>& ptr) {     game_objects.erase(game_objects.find(ptr));     ptr.reset(); }  std::shared_ptr<r3d::game_object>& scene::get_object(const char* name) {     for(const auto& object : game_objects)     {         if(object->name == name)         {             return object;         }     }      return nullptr; } 

game_object.hpp

namespace r3d {     class game_object     {     public:         const char* name;          game_object(const char* name, glm::vec3 position, glm::vec3 euler_angles, glm::vec3 scale);          ~game_object()         {             std::cout << "delete game_object\n" << std::endl;         }      protected:         glm::vec3 position;         glm::vec3 euler_angles;         glm::vec3 scale;     }; } 

Calling remove_object() from main.cpp will remove both shared_ptr’s and call game_object’s destructor, all good, however I cannot remove the object from a different class as main.cpp will hang on to the shared_ptr.

There seems to be a few options here, I’m thinking it may be better to make obj a unique_ptr and move ownership to scene.cpp, passing back a reference to main.cpp so it can still observe the object, and have this reference for removing it.