Get SpatialOS

Sites

Menu
These are the docs for 13.2, an old version of SpatialOS. 13.3 is the newest →

Schema introduction

The schema is where you define all the components that entities in your SpatialOS world can have.

For information about how to design what goes into components, see Designing components.

We also recommend reading Component best practices.

Writing .schema files

Define components in .schema files, written in schemalang. Schema files are stored in the schema/ directory.

For information how to write schema files, see the schemalang reference page.

Generating code from the schema

SpatialOS uses the schema to generate code in various languages (including C#, C++, and Java). You use this generated code in your worker code to interact with the entities in the world.

There are two ways to generate code: using the CLI, or using the schema compiler directly.

Using the CLI

To generate code, you can use the command spatial worker codegen. This will execute the build steps specified in your worker build configuration file.

Using the schema compiler directly

If you are using the flexible project layout (currently in alpha), you can use the schema compiler directly. You first need to retrieve the package using:

spatial package retrieve tools schema_compiler-x86_64-{PLATFORM} <SDK version> schema_compiler-x86_64-{PLATFORM}.zip

Remember to specify your SDK version, and replace PLATFORM with win32, linux or macos.

You can then call the schema compiler with these arguments:

./schema_compiler --schema_path=... [arguments] input_files

Argument Description
--schema_path=<path_to_directory> Root path where the schema files you want to compile are stored
--load_all_schema_on_schema_path Loads all schema files in the path and validates they are semantically correct
--print_components Prints the components in your schema on the standard output as they are generated
--dependency_out=<path_to_file> Dumps the dependencies to a file
--ast_json_out=<path_to_directory> Dumps the AST in JSON format in a directory
--cpp_out=<path_to_directory> Generates C++ code from the schema to a directory
--csharp_out=<path_to_directory> Generates C# code from the schema to a directory
--java_out=<path_to_directory> Generates Java code from the schema to a directory
--typescript_out=<path_to_directory> Generates TypeScript code from the schema to a directory
--descriptor_set_out=<path_to_directory> Generates a protobuf descriptor file, used internally by the Runtime

Using the generated code

For details on how to use the generated code to send and receive component updates, see the docs for your SDK:

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums