Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Fix editor unable to play game after IDE PlayRequest #41362

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions modules/mono/editor/GodotTools/GodotTools/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,8 @@ public static bool EditorBuildCallback()
if (File.Exists(editorScriptsMetadataPath))
File.Copy(editorScriptsMetadataPath, playerScriptsMetadataPath);

var currentPlayRequest = GodotSharpEditor.Instance.CurrentPlaySettings;

if (currentPlayRequest != null)
{
if (currentPlayRequest.Value.HasDebugger)
{
// Set the environment variable that will tell the player to connect to the IDE debugger
// TODO: We should probably add a better way to do this
Environment.SetEnvironmentVariable("GODOT_MONO_DEBUGGER_AGENT",
"--debugger-agent=transport=dt_socket" +
$",address={currentPlayRequest.Value.DebuggerHost}:{currentPlayRequest.Value.DebuggerPort}" +
",server=n");
}

if (!currentPlayRequest.Value.BuildBeforePlaying)
return true; // Requested play from an external editor/IDE which already built the project
}
if (GodotSharpEditor.Instance.SkipBuildBeforePlaying)
return true; // Requested play from an external editor/IDE which already built the project

return BuildProjectBlocking("Debug");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class GodotSharpEditor : EditorPlugin, ISerializationListener

public BottomPanel BottomPanel { get; private set; }

public PlaySettings? CurrentPlaySettings { get; set; }
public bool SkipBuildBeforePlaying { get; set; } = false;

public static string ProjectAssemblyName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,10 @@ private static Task<Response> HandlePlay()
{
DispatchToMainThread(() =>
{
GodotSharpEditor.Instance.CurrentPlaySettings = new PlaySettings();
// TODO: Add BuildBeforePlaying flag to PlayRequest

// Run the game
Internal.EditorRunPlay();
GodotSharpEditor.Instance.CurrentPlaySettings = null;
});
return Task.FromResult<Response>(new PlayResponse());
}
Expand All @@ -341,10 +342,22 @@ private static Task<Response> HandleDebugPlay(DebugPlayRequest request)
{
DispatchToMainThread(() =>
{
GodotSharpEditor.Instance.CurrentPlaySettings =
new PlaySettings(request.DebuggerHost, request.DebuggerPort, request.BuildBeforePlaying ?? true);
// Tell the build callback whether the editor already built the solution or not
GodotSharpEditor.Instance.SkipBuildBeforePlaying = !(request.BuildBeforePlaying ?? true);

// Pass the debugger agent settings to the player via an environment variables
// TODO: It would be better if this was an argument in EditorRunPlay instead
Environment.SetEnvironmentVariable("GODOT_MONO_DEBUGGER_AGENT",
"--debugger-agent=transport=dt_socket" +
$",address={request.DebuggerHost}:{request.DebuggerPort}" +
",server=n");

// Run the game
Internal.EditorRunPlay();
GodotSharpEditor.Instance.CurrentPlaySettings = null;

// Restore normal settings
Environment.SetEnvironmentVariable("GODOT_MONO_DEBUGGER_AGENT", "");
GodotSharpEditor.Instance.SkipBuildBeforePlaying = false;
});
return Task.FromResult<Response>(new DebugPlayResponse());
}
Expand Down