- Home /
Dragwindow can only be called within a window callback
I tried to move GUI.DragWindow() to a separate function as a way to conditionally draw a stand-alone window depending on whether the GUI element was a child of another element. Although the drag window behavior works properly, Unity generates the following recurring error at runtime:
Dragwindow can only be called within a window callback
Is there a reason why Unity claims it can't handle the window callback calling another function?
public delegate void AggregateDraw();
AggregateDraw standaloneWindowContent;
standaloneWindowContent = () =>
{
GUI.DragWindow();
};
public void Draw()
{
rect = GUI.Window(containerID, rect, DrawWindowContent, actionName);
}
void DrawWindowContent(int id)
{
standaloneWindowContent();
}
Answer by Bunny83 · Oct 07, 2017 at 10:49 AM
Well, where do you call your "Draw" method? That's most likely the important part. When i copy& paste your code into my test project and call Draw from OnGUI everything works just fine without any error or warning.
Some code pixies visited after I called it a night. (^_^)
I now realize that some debug code I had forgotten to take out was directly calling DrawWindowContent(id) from Draw() in addition to invoking it as a callback through the GUI.Window API.
Great :)
If you stumble on such a problem again, keep in $$anonymous$$d that most errors and all Debug.Logs have a full stacktrace attached. So if you see an error you can actually see from where the offending code was called.
Your answer
![](https://koobas.hobune.stream/wayback/20220612140442im_/https://answers.unity.com/themes/thub/images/avi.jpg)