Skip to end of metadata
Go to start of metadata

Overview

This section contains documentation about how to use C# to develop your game in 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 CRYENGINE, or to quickly get started with developing your CRYENGINE game in C#.

Getting Started

CRYENGINE supports two ways of working with C#, managed plugins and C# assets. Managed plugins are stand-alone plugins that can be imported into multiple projects. C# assets are C# files that are in the assets folder of your project, and are compiled automatically by the Sandbox. To start working with either the managed plugins or C# assets you will first have to create a new project.

The steps below assume that you already have a CRYENGINE account and have installed the most up to date version of the CRYENGINE Launcher and CRYENGINE.

  1. Open the CRYENGINE Launcher from the icon on your desktop and login to your account.
  2. Click the +NEW option in the Projects section (top left-hand side of the Launcher window).
  3. Select the C# tab - this will reveal the templates that are available to you.
  4. Select the template that you require.
  5. Select a location where it will be located on your PC and choose a name for your project. Finally, click Create Project.

Icon

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, 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 you to register your engine, select Yes.

Icon

The generated C# solution for managed plugins and C# assets 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.

Managed plugin

The solution for a managed plugin needs to be generated first before you can start programming.

  1. To start programming, mouse over the relevant project name (left-hand side of the Launcher window) which will reveal a Settings icon . Click the icon and then click on Reveal in Explorer.
  2. This takes you to the folder where your project is located. Double click on the folder and this will expose  other folders including the relevant template.
  3. Right click the Game.cryproject file in this folder and then click Generate solution.
  4. Open the Code folder and run the Game.sln file with a CRYENGINE compatible editor, such as Visual Studio 2017.

C# Assets

For the C# assets you don't need to generate and compile the solution yourself. Instead it's all done by the Sandbox whenever the files have changed. To get started you simply open the Sandbox and right-click in the Asset Browser. In the menu select New...→C# Script which will create a new C# file in the Asset Browser. You can open the file by double-clicking it which will open a C# solution that contains the C# file.

Icon

By default the solution is opened with Visual Studio. If you want to open the solution with another IDE, or if you want to open the file directly instead of the solution, you can change this in the settings by going to Edit→Preferences...→General→File.

Developing in the CRYENGINE with C#

The C# project files have a special ProjectTypeGuid to identify them as CRYENGINE projects. This makes it possible for the CRYENGINE extension to attach the debugger to the CRYENGINE which is not possible by default. However, this also means that it's not possible to open the projects without the CRYENGINE extension.

Visual Studio 2017

To work with Visual Studio 2017 you first need to install the CRYENGINE extension for Visual Studio. This can be done by running the installer found at <engine-root>/Tools/VisualStudioExtensions/CryEngine.Debugger.Mono.vsix. After installing the extension you will be able to open the C# solution of the CRYENGINE.

With the extension installed, if you open a CRYENGINE solution you'll notice that the default Start button has changed to Debug GameLauncher. Pressing this button (or starting debugging with a hotkey) will now launch the GameLauncher and attach to it at the start. You can also press the dropdown-menu on the Start button to select other debug targets, for example the Sandbox or the dedicated server. These targets can also be changed from the Debug menu in Visual Studio. Switching the target will make either the GameLauncher.exe, Sandbox.exe or Game_Server.exe start, when debugging is started.

At the moment it's not yet possible to attach to an already running instance of the CRYENGINE.

Older versions of Visual Studio

The C# project files have a special ProjectTypeGuid to identify them as CRYENGINE projects. This makes it possible for the CRYENGINE extension to attach the debugger to the CRYENGINE which is not possible by default.

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.

Now search for the following line:

Replace the line with:

Save the file. You can now open the solution file in Visual Studio.

Icon

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.

Xamarin Studio

Icon

On May 10, 2017 the final release of Xamarin Studio was released, and with that the development of the Xamarin Studio add-in has also been discontinued. We recommend switching to the Visual Studio 2017 extension.

 

The CRYENGINE add-in for Xamarin Studio allows for running and debugging CRYENGINE C# projects with Xamarin Studio.

  1. Install Xamarin Studio by following the instructions on the Xamarin Studio download page.
  2. 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.
  3. To install the add-in, select Tools→Add-ins... in the menu-bar at the top.
  4. Press Install from file... at the bottom of the window.
  5. 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.

At 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.

Chapters:

Related Content:

  • No labels