Selection from script triggers Undo

Hi,

I am trying to set the Selection from script. I instantiate an object from script and want to drag and drop it in the scene. As soon as I get the DragUpdated event from the SceneView, I want to set the Selection to the instantiated object. However, Unity automatically calls an Undo right after setting the Selection. Resulting in the inspector showing for 1 frame and then being undone.

When I set the Selection on creating the object, this goes fine, no Undo. This is done during an mouseDown event.
When I set the Selection on DragUpdated, it triggers the Undo.

This is what that looks like:
8106596--1049567--Unity_lGw8avQcYC.gif

Why is this, and how can I maybe avoid this?

Nobody has any idea as to why this weird thing happens? :confused:

Please help me in my quest!

:frowning: