Page MenuHome

'context.scene' not updating correctly from prop update function
Closed, InvalidPublic


System Information
Operating system:
Graphics card:

Blender Version
Broken: 2.8x (tested 2.80, 2.83), 2.90
Worked: Never

Short description of error

When the active scene is changed by a property updater from the 'Scene' panel context, the context.scene property of the operator's context is not updated correctly. Similar to T75352, though cannot be fixed with the resolution described there.

Exact steps for others to reproduce the error

  • Open the default startup file
  • Run the following script:
import bpy

# create panel
class SCENE_PT_test_case(bpy.types.Panel):
    bl_space_type  = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_label       = "TEST CASE"
    bl_idname      = "SCENE_PT_test_case"
    bl_context     = "scene"

    def draw(self, context):
        scn = context.scene
        self.layout.prop(scn, "test_prop")

# define property update function
def new_scn(self, context):
    scn ="My Scene_" + str(context.scene.test_prop)) ="My World")
    context.window.scene = scn

# register
bpy.types.Scene.test_prop = bpy.props.IntProperty(
  • Navigate to the 'Render' properties panel, and scroll down to the new tab titled "TEST CASE".
  • Change the test_prop integer to something different. This will trigger the new_scn update function, which creates a new scene and sets it to the active scene. If it worked correctly, the names printed to the console should match.

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Mon, Sep 14, 6:44 PM

I can confirm, ...

Please do so :)

Campbell Barton (campbellbarton) closed this task as Invalid.EditedTue, Sep 15, 9:14 AM

Checking on this, it would require a refresh/redraw of the UI immediately after setting the active scene, so the properties-editor updates the Scene path.

Closing this since depending on the context isn't likely to work well, the user may - for example pin the scene in the properties editor, so even if it was made to update in some cases, it wouldn't work reliably.

Note that, setting the scene from a properties update callback seems quite error prone too.