Getting currently selected vertex in Modal properly?


It seems like the currently selected vertex is not registered by the time when a mouse is clicked to select if the operator is modal. I am wondering what the proper way to do this is.

Here is a sample code. In this example, the Cursor moves to the selected vertex after a second click, this click can be done on another component or the viewport, it seems to require some kind of update I assume. So when the user clicks on vertex the cursor does not moved to that one immeidately.

#Assumes the user clicks on a componnet
  if event.type == 'LEFTMOUSE':
            print("Left mouse")
            if context.object.mode=='EDIT':

            return {'PASS_THROUGH'}


It looks like Blender passes a NOTHING event when nothing happens. You could use that event to run updates. and other events to set things up.

Try starting Blender with --debug-all to see the events that Blender handles.

1 Like

this is a textbook race condition. you have two different operators firing simultaneously and one requires the other to work. Iā€™m not sure what your operator does, so proposing solutions will be flying blind at best, but you could handle the component selection from within your modal operator, thus ensuring the data is correct before you use it. this could be as simple as monitoring for the LEFTMOUSE event, then calling, then snap the cursor, then return running_modal instead of pass_through.

1 Like