This section contains documentation about how to use C# to develop your game in the CRYENGINE, and provides more information about the templates and example projects. To jump right into it, the CRYENGINE Launcher provides several templates to get you familiar with C# in the CRYENGINE, or to quickly get started with developing your CRYENGINE game in C#.
The below steps assume that you already have a CRYENGINE account and have installed the most up to date version of the CRYENGINE Launcher and CRYENGINE.
Open the CRYENGINE Launcher from the icon on your desktop, then login to your CRYENGINE account.
Click the +NEW option in the Projects section(top left-hand side of the Launcher window).
Select the C# tab - this will reveal the templates that are available to you.
Select the template that you require.
Select a location where it will be located on your PC and then choose a name for your project, and finally click Create Project.
If you're using the engine-source from Github, you can create a new project by copying the template you want from <root>/Code/GameTemplates/cs/ to the location where you want your project to be in your system. Once it is copied then open the game.cryproject file in Notepad and change the value of "name" to the name of your project. After changing the name, right-click the game.cryproject file and select Switch Engine and set it to the root-folder of your engine. If it asks to register your engine select Yes.
Once the project is created, the C# solution file needs to be generated first before you can start programming.
To start programming, mouse over the relevant project name (left-hand side of the Launcher window) which will reveal a Settings icon . Click on the icon, then click on Reveal in Explorer.
This takes you to the folder where your project is located. Double click on the folder, this will expose other folders including the relevant template. Right click the Game.cryproject file in this folder.
Right click on that file and then click Generate solution.
Open the Code folder and run the Game.sln file with a CRYENGINE compatible editor, such as Xamarin Studio.
The generated C# solution is a special CRYENGINE C# project, which can only be opened by editors with the CRYENGINE-extension. Opening the solution with an unsupported editor can result in unexpected behavior and corruption of data.
Running C# in Xamarin Studio
The CRYENGINE add-in for Xamarin Studio allows for running and debugging CRYENGINE C# projects with Xamarin Studio.
Install Xamarin Studio by following the instructions on the Xamarin Studio download page.
Open Xamarin Studio and make sure it is updated to at least version 6.2. You can check the version in the menu-bar at the top in Help→About. To update it select Help→Check for Updates from the same menu-bar.
To install the add-in select Tools→Add-ins... in the menu-bar at the top.
Press Install from file... at the bottom of the window.
Browse to <engine-root>/Tools/XamarinStudioAddin/ and select MonoDevelop.CryEngine.mpack to install the add-in.
Now, whenever you open a CRYENGINE C# solution the add-in will automatically locate the CRYENGINE and set the right mono-runtime.
In the top-left of Xamarin Studio, click the new dropdown-menu, where you can select to start the GameLauncher, the Sandbox or the Server. By pressing F5, the add-in will start the current project with the selected launcher. While the application is being launched Xamarin Studio will attach itself to the application. Once the project is running, you can start debugging the application by adding breakpoints in your code.
Running C# in Visual Studio 2015 & 2017
The C# project files have a special ProjectTypeGuid to identify them as CRYENGINE projects. This makes it possible for the CRYENGINE add-in to attach the debugger to the CRYENGINE which is not possible by default. The CRYENGINE add-in for Visual Studio is currently in development. This means that at the moment it is not possible to debug your C# project in Visual Studio.
You can however adjust the .csproj file of your project to make it possible for Visual Studio to open the solution.
First generate the solution as described in Getting Started.
In your code folder, open the generated .csproj files with a text-editor like Notepad++ or Visual Studio Code.
Search for the following line:
Replace the line with:
Save the file. You should now be able to open the solution file in Visual Studio.
Every time the solution is generated again by right clicking the .cryproject file and pressing Generate Solution the ProjectTypeGuids will reset, so make sure to adjust the .csproj files again.