Table of Contents

Create Project

Command Line and Visual Studio Code Instructions

The following instructions will guide you through the process of creating a new Stride project using the command line. If you prefer to use Visual Studio Code, you can follow the same instructions in the Visual Studio Code Terminal.

  1. Prerequisites: Make sure you have all prerequisites installed. See the Prerequisites section for more information.
  2. Create a Console App: Follow the Microsoft tutorial to learn more about how to create a new console application.
    dotnet new console --framework net8.0
    
  3. Add NuGet Package: Execute the following command to add the necessary NuGet package.
    dotnet add package Stride.CommunityToolkit --prerelease
    
  4. Update Program.cs: Paste the example code (below) into your Program.cs file.
  5. Build the Project (Optional): The dotnet build command is used to compile your Stride project, generating executable files and checking for any errors in your code. This step is optional as the subsequent dotnet run command will automatically build the project if it hasn't been built already. To manually build the project, execute the following command:
    dotnet build
    
  6. Run the Project: The dotnet run command will build (if necessary) and execute your project. Run the following command to start your Stride project:
    dotnet run
    
  7. Enjoy Stride: If everything is set up correctly, you should now be able to run and enjoy your Stride project.

Visual Studio 2022 and Rider Instructions

  1. Create a C# Console Application: Open Visual Studio 2022 or Rider and create a new C# Console Application targeting .NET 8.
  2. Add NuGet Package: Search for and add the Stride.CommunityToolkit NuGet package, ensuring you opt for the pre-release version.
    • This package will install all needed Stride NuGet packages
  3. Update Program.cs: Paste the example code (provided below) into your Program.cs file.
  4. Run the Project: Build and run your project using the IDE's run functionality.
  5. Enjoy Stride: If everything is set up correctly, you should now be able to run and enjoy your Stride project.

Example Code

The provided C# code example is designed to showcase the basic usage of the Stride Game Engine.

using Stride.CommunityToolkit.Engine;
using Stride.CommunityToolkit.Rendering.ProceduralModels;
using Stride.Core.Mathematics;
using Stride.Engine;

using var game = new Game();

game.Run(start: Start);

void Start(Scene rootScene)
{
    game.SetupBase3DScene();

    var entity = game.Create3DPrimitive(PrimitiveModelType.Capsule);

    entity.Transform.Position = new Vector3(0, 8, 0);

    entity.Scene = rootScene;
}
  1. using var game = new Game(); creates a new instance of the Game class.
  2. The game.Run(start: Start); line starts the game, and it specifies that the Start method should be called when the game begins.
  3. void Start(Scene rootScene) is the method that is called when the game starts. It takes in a Scene object, which represents the game scene that is currently being played.
  4. Inside the Start method, game.SetupBase3DScene(); sets up a basic 3D scene.
  5. var entity = game.Create3DPrimitive(PrimitiveModelType.Capsule); creates a new primitive entity of type Capsule, and assigns it to the entity variable.
  6. entity.Transform.Position = new Vector3(0, 8, 0); sets the position of the entity in the 3D space. The position is set to (0, 8, 0), which means the capsule is placed 8 units above the ground.
  7. entity.Scene = rootScene; adds the entity to the root scene of the game.

The Create3DPrimitive() method creates a Capsule with rigid body physics. Because the capsule is placed 8 units above the ground, it will fall due to gravity. Note that it's important to remove the capsule from memory once it's no longer visible in the scene, to free up resources and ensure the CPU isn't unnecessarily calculating physics for it

image

Additional Examples

Explore more examples listed in the menu on the left, categorized by the programming language and level of complexity. These examples provide a deeper understanding of how to work with a code-only project in Stride, showcasing various functionalities and implementations.

The examples are organized under the following sections:

  • C# Basic Examples: Contains basic examples demonstrating fundamental concepts using C#.
  • C# Advanced Examples: Features more advanced scenarios and implementations using C#.
  • F# Basic Examples: Basic examples showcasing fundamental concepts using F#.
  • VB Basic Examples: Demonstrates fundamental concepts using Visual Basic.

To view an example, click on its name in the menu, and you will be navigated to a page with a detailed explanation and code snippets.