Skip to content

Commit

Permalink
Update WORKING_WITH_CSHARP.md
Browse files Browse the repository at this point in the history
Updates links to the main branch and other minor tweaks.
  • Loading branch information
Ivan-267 authored May 12, 2024
1 parent fd7748d commit 22c459a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions docs/WORKING_WITH_CSHARP.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ it is possible to use C# for your projects as well. The process is slightly more
how the gdscript variant of the plugin works is recommended.

We recommended completing the [custom env](https://github.com/edbeeching/godot_rl_agents/blob/main/docs/CUSTOM_ENV.md) tutorial first using
gdscript to get an idea of the usual process with gdscript first.
gdscript to get an idea of the usual process first.

We have prepared a simple example that comes in 3 variants:
- GDScript [TODO: LINK] (The entire game is written in gdscript)
- CSharp [TODO: LINK] (Most of the game is written in C#, except for the extended AIController which is written in GDScript)
- CSharpAll [TODO: LINK] (The entire game is written in C#, and interfacing with the plugin is done through an AIController also written in C#)
- [GDScript](https://github.com/edbeeching/godot_rl_agents_examples/tree/main/examples/TestExamples/SimpleReachGoal/GDScript) (The entire game is written in gdscript)
- [CSharp](https://github.com/edbeeching/godot_rl_agents_examples/tree/main/examples/TestExamples/SimpleReachGoal/CSharp) (Most of the game is written in C#, except for the extended AIController which is written in GDScript)
- [CSharpAll](https://github.com/edbeeching/godot_rl_agents_examples/tree/main/examples/TestExamples/SimpleReachGoal/CSharpAll) (The entire game is written in C#, and interfacing with the plugin is done through an AIController also written in C#)

### CSharp

In this approach, we extend the AIController using gdscript as we cannot directly extend from it using C#, but we still write the rest of the game in C# (e.g. Player and other classes).

You can see the [extended AIController here](https://github.com/edbeeching/godot_rl_agents_examples/blob/AddSimpleTestEnv/examples/TestExamples/SimpleReachGoal/CSharp/scenes/player/player_ai_controller.gd). The code is very similar to the gdscript env version [extended AI Controller](https://github.com/edbeeching/godot_rl_agents_examples/blob/AddSimpleTestEnv/examples/TestExamples/SimpleReachGoal/GDScript/scenes/player/player_ai_controller.gd), except that we don't get code completion for the C# classes. It is slightly more complex to access/modify the AIController properties from the C# Player class, and you can see how that is done in the [Player script](https://github.com/edbeeching/godot_rl_agents_examples/blob/AddSimpleTestEnv/examples/TestExamples/SimpleReachGoal/CSharp/scenes/player/Player.cs).
You can see the [extended AIController here](https://github.com/edbeeching/godot_rl_agents_examples/blob/main/examples/TestExamples/SimpleReachGoal/CSharp/scenes/player/player_ai_controller.gd). The code is very similar to the gdscript version [extended AI Controller](https://github.com/edbeeching/godot_rl_agents_examples/blob/main/examples/TestExamples/SimpleReachGoal/GDScript/scenes/player/player_ai_controller.gd), except that we don't get code completion in gdscript for the C# classes. It is slightly more complex to access/modify the gdscript AIController properties from the C# Player class, and you can see how that is done in the [Player script](https://github.com/edbeeching/godot_rl_agents_examples/blob/main/examples/TestExamples/SimpleReachGoal/CSharp/scenes/player/Player.cs).

The main advantage of this approach is that it doesn't require any modifications to the plugin, or writing an AIController wrapper (see [CSharpAll](#csharpall) for that approach). It's also easy to access data from [sensors](https://github.com/edbeeching/godot_rl_agents/blob/main/docs/NODE_REFERENCE.md#sensors) included in the plugin which are written in gdscript. The disadvantage is that it uses [cross-language scripting](https://docs.godotengine.org/en/stable/tutorials/scripting/cross_language_scripting.html) when interfacing between the AIController and the Player script and/or the rest of the env code written in C#.

Expand All @@ -27,12 +27,10 @@ consistent experience for C# developers. The main advantage of this approach is
no longer assumes [cross-language scripting](https://docs.godotengine.org/en/stable/tutorials/scripting/cross_language_scripting.html) between C# and GDScript.

This approach is slightly more complicated to set up than the _CSharp_ variant, as it requires a custom C# wrapper for
the `ai_controller_3d.gd` node. We provide this wrapper called `AIControllerSharp3D.cs` [here](https://github.com/edbeeching/godot_rl_agents_examples/blob/AddSimpleTestEnv/examples/TestExamples/SimpleReachGoal/CSharpAll/scenes/player/AIControllerSharp3D.cs),
the `ai_controller_3d.gd` node. We provide this wrapper called `AIControllerSharp3D.cs` [here](https://github.com/edbeeching/godot_rl_agents_examples/blob/main/examples/TestExamples/SimpleReachGoal/CSharpAll/scenes/player/AIControllerSharp3D.cs),
but it should be noted that this wrapper may not be kept up to date with the GDScript version, as such it may need small
changes in the future to work.

[//]: # "TODO: Change `AIControllerSharp3D.cs` branch infix to main when merged"

#### Using the C# AIController

As we did in the other examples, we need to inherit from the AIController node, only now we will inherit from the
Expand All @@ -42,9 +40,7 @@ need to add logic to, see this section of [custom env](https://github.com/edbeec
As mentioned before, by writing the AIController in C# we eliminate [cross-language scripting](https://docs.godotengine.org/en/stable/tutorials/scripting/cross_language_scripting.html) between the 'player'
C# script and the AIController script, but this does mean that interfacing with other GDScript nodes, such as the
sensors provided by the plugin, means a minimal cross-language scripting is still required. This example also showcases
how to inferface with these components (see [PlayerAIController.cs](https://github.com/edbeeching/godot_rl_agents_examples/blob/AddSimpleTestEnv/examples/TestExamples/SimpleReachGoal/CSharpAll/scenes/player/PlayerAIController.cs)).

[//]: # "TODO: Change `PlayerAIController` branch infix to main when merged"
how to inferface with these components (see [PlayerAIController.cs](https://github.com/edbeeching/godot_rl_agents_examples/blob/main/examples/TestExamples/SimpleReachGoal/CSharpAll/scenes/player/PlayerAIController.cs)).

#### Modifying the AIController 3D wrapper to 2D version

Expand Down

0 comments on commit 22c459a

Please sign in to comment.