diff --git a/docs/sphinx/reference-scenes.rst b/docs/sphinx/reference-scenes.rst index 6cacf33ad..71b584cf2 100644 --- a/docs/sphinx/reference-scenes.rst +++ b/docs/sphinx/reference-scenes.rst @@ -225,6 +225,16 @@ General Scene Functions --------------------- +.. function:: obs_sceneitem_t *obs_scene_find_source_recursive(obs_scene_t *scene, const char *name) + + Same as obs_scene_find_source, but also searches groups within the + scene. + + :param name: The name of the source to find + :return: The scene item if found, otherwise *NULL* if not found + +--------------------- + .. function:: obs_sceneitem_t *obs_scene_find_sceneitem_by_id(obs_scene_t *scene, int64_t id) :param id: The unique numeric identifier of the scene item diff --git a/libobs/obs-scene.c b/libobs/obs-scene.c index dafae0037..294c64ff7 100644 --- a/libobs/obs-scene.c +++ b/libobs/obs-scene.c @@ -1445,6 +1445,39 @@ obs_sceneitem_t *obs_scene_find_source(obs_scene_t *scene, const char *name) return item; } +obs_sceneitem_t *obs_scene_find_source_recursive(obs_scene_t *scene, + const char *name) +{ + struct obs_scene_item *item; + + if (!scene) + return NULL; + + full_lock(scene); + + item = scene->first_item; + while (item) { + if (strcmp(item->source->context.name, name) == 0) + break; + + if (item->is_group) { + obs_scene_t *group = item->source->context.data; + obs_sceneitem_t *child = + obs_scene_find_source(group, name); + if (child) { + item = child; + break; + } + } + + item = item->next; + } + + full_unlock(scene); + + return item; +} + obs_sceneitem_t *obs_scene_find_sceneitem_by_id(obs_scene_t *scene, int64_t id) { struct obs_scene_item *item; diff --git a/libobs/obs.h b/libobs/obs.h index cccae2236..401d5ff5a 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -1450,6 +1450,9 @@ EXPORT obs_scene_t *obs_scene_from_source(const obs_source_t *source); EXPORT obs_sceneitem_t *obs_scene_find_source(obs_scene_t *scene, const char *name); +EXPORT obs_sceneitem_t *obs_scene_find_source_recursive(obs_scene_t *scene, + const char *name); + EXPORT obs_sceneitem_t *obs_scene_find_sceneitem_by_id(obs_scene_t *scene, int64_t id);