OBS Studio crashing when switched to scene (Python Script)

Nocticae

New Member
Hi,

I have a problem with my python script...
I've got 4 scenes : 'Scene_0' à 'Scene_3'

Situation 1 :
I'm in scene 'Scene_0' when I switch to scene 'Scene_1'
The script returns me to the 'Scene_2' scene.

In this situation, the program works perfectly.

Situation 2 :
I'm in scene 'Scene_0' when I switch to scene 'Scene_3'
After 10 seconds, the script normally returns me to the 'Scene_2' scene.

But in this case, the application no longer responds, I don't know why there's
no error message, no crash log, nothing.

Here's the code :

Python:
import obspython as obs

### Variables ###
countdown_time = 0
################

###### OBS ######
def script_description():
    return "Un script de compte à rebours pour OBS Studio."

def on_event(event):
    if event == obs.OBS_FRONTEND_EVENT_SCENE_CHANGED:
        assigning_functions_to_scenes()

def script_load(settings):
    obs.obs_frontend_add_event_callback(on_event)
#################

##### Scipts #####

def get_currentscene() -> str:
    """Gets the current scene and returns its name"""
    current_scene_as_source = obs.obs_frontend_get_current_scene()
    current_scene_name = obs.obs_source_get_name(current_scene_as_source)
    obs.obs_source_release(current_scene_as_source)

    return current_scene_name

def set_scene(scene_name: str):
    """Gets scene name and set new current scene"""
    source = obs.obs_get_source_by_name(scene_name)
    if source is not None:
        obs.obs_frontend_set_current_scene(source)
        obs.obs_source_release(source)


def assigning_functions_to_scenes():
    """Calls a function according to the current scene"""
    Current_Scene = get_currentscene()

    if Current_Scene == "Scene_1":
        set_scene("Scene_2")

    elif Current_Scene == "Scene_3":
        global countdown_time
        countdown_time = 10
        obs.timer_add(Countdown_to_scene_change, 1000)

def Countdown_to_scene_change():
    """Countdown which at the end will call the set_scene function"""
    global countdown_time

    if countdown_time > 0:
        countdown_time -= 1

    else:
        obs.timer_remove(Countdown_to_scene_change)
        set_scene("Scene_2")

##################
 

AaronD

Active Member
The Advanced Scene Switcher plugin can probably do all that for you, and it's pretty well tested already.
  • Macro 1
    • Conditions
      • Current scene = Scene 1
    • Actions
      • Switch to Scene 2
  • Macro 2
    • Conditions
      • Current scene = Scene 3 for 10 seconds
    • Actions
      • Switch to Scene 2
It seems odd to switch immediately away from a scene every time you enter it. Is there a reason for that? Why not switch directly to Scene 2, and not even have Scene 1?
 
Top