Create a script

You can create scripts using Game Studio or an IDE such as Visual Studio.

  • In the Asset View, click Add asset > Scripts and select a script type.

Note

For information about different types of script, see .

The New script dialog opens.

New script

  • Specify a class and namespace for the script and click Create script.

  • To use the script, you need to save it. By default, Game Studio prompts you to save the script now.

After you save the script, you can see it in the Asset View.

Note

Although scripts are a kind of asset, they're not saved in the Assets folder. Instead, they're saved in the relevant assembly folder. For more information, see Project structure.

Tip

To open your solution in Visual Studio from Game Studio, click the Open in IDE (Open in IDE) icon in the Game Studio toolbar.

  • Open Visual Studio.
Tip

To open your solution in Visual Studio from Game Studio, click the (Open in IDE) icon in the Game Studio toolbar.

The game solution is composed of several projects:

  • The project ending .Game is the main project, and should contain all your game logic and scripts.

  • Other projects (eg MyGame.Windows, MyGame.Android etc) contain platform-specific code.

For more information, see .

  • Add a new class file to the project. To do this, right-click the project and select Add > New Item.

    The Add New Item dialog opens.

Visual Studio adds a new class to your project.

  • In the file you created, make sure the script is public and derives from either AsyncScript or SyncScript.

  • Implement the necessary abstract methods.

    For example:

  1. using System;
  2. using System.Text;
  3. using System.Threading.Tasks;
  4. using Xenko.Core.Mathematics;
  5. using Xenko.Input;
  6. using Xenko.Engine;
  7. namespace MyGame
  8. {
  9. public class SampleSyncScript : SyncScript
  10. {
  11. public override void Update()
  12. {
  13. {
  14. // Do something every frame
  15. }
  16. }
  17. }
  18. }
  • Save the project and script files.

  • Because you modified the script, Game Studio needs to reload the assembly to show the changes.

Confirmation message

Click Yes.

You can see the script in the Asset View.

Note

Although scripts are a kind of asset, they're not saved in the Assets folder. Instead, they're saved in the relevant assembly folder. For more information, see Project structure.