def spawn_object(self, object_class, force_spawn=False, auto_fill_random_seed=True, record=True, **kwargs):
        """
        Call this func to spawn one object
        :param object_class: object class
        :param force_spawn: spawn a new object instead of fetching from _dying_objects list
        :param auto_fill_random_seed: whether to set random seed using purely random integer
        :param record: record the spawn information
        :param kwargs: class init parameters
        :return: object spawned
        """
        if ("random_seed" not in kwargs) and auto_fill_random_seed:
            kwargs["random_seed"] = self.generate_seed()
        if force_spawn or object_class.__name__ not in self._dying_objects or len(
                self._dying_objects[object_class.__name__]) == 0:
            obj = object_class(**kwargs)
        else:
            obj = self._dying_objects[object_class.__name__].pop()
            obj.reset(**kwargs)
            if not is_map_related_class(object_class) and ("name" not in kwargs or kwargs["name"] is None):
                obj.random_rename()

        if "name" in kwargs and kwargs["name"] is not None:
            assert kwargs["name"] == obj.name == obj.id
        if "id" in kwargs and kwargs["name"] is not None:
            assert kwargs["id"] == obj.id == obj.name

        if self.global_config["record_episode"] and not self.replay_episode and record:
            self.record_manager.add_spawn_info(obj, object_class, kwargs)
        self._spawned_objects[obj.id] = obj
        color = self._pick_color(obj.id)
        if color == (-1, -1, -1):
            raise ValueError(
                "No color available for object: {} instance segment mask. We already used all {} colors...".format(
                    obj.id, BaseEngine.MAX_COLOR
                )
            )

        obj.attach_to_world(self.worldNP, self.physics_world)
        return obj

        Call this func to spawn one object
        :param object_class: object class
        :param force_spawn: spawn a new object instead of fetching from _dying_objects list
        :param auto_fill_random_seed: whether to set random seed using purely random integer
        :param record: record the spawn information
        :param kwargs: class init parameters
        :return: object spawned
        
metadrive/engine/base_engine.py