The most important part of every game are Scripts. Creating chunks of code that handle game events, respond to user input, and control objects is an essential ingredient in all games. In short, scripts make games interactive by adding gameplay. It applies to both small and huge production. This documentation section covers the most important parts of the scripting pipeline and helps with starting the game programming.
Flax supports C#, C++ and Visual scripting. The mix of those three languages is highly integrated into the engine as it's written in those languages (engine is C++, editor is C#).
Note
Explaining C#, C++ and vector math is out of the scope of this documentation.
Important concepts related to programming in Flax are binary modules. Binary modules are compiled source code libraries that can reference other modules (eg. Editor, Graphics, or plugins).
In most cases, the main game code is in the module named <project_name>
or named Game
located in Source
folder (eg. Source/Game
). That's the place where you can add new scripts so build tool will compile them. For more, advanced uses game can contain multiple modules and have code split for better organization (as for example engine does - it's made of multiple modules working together). For instance, you can create an editor-only module and use its code only in the Editor.
To learn more about build tools and infrastructure see Flax.Build utility documentation.
You can write scripts in C# and add them to scene objects. To learn more about it see the pages in this section. Most of the documentation related to scripting covers C# to implement various gameplay logic. If you need help with learning C# see this page.
Flax uses Mono to load, compile and execute C# scripts. Currently the newest C# 7.2 version is fully supported (with .Net Framework 4.5). Flax Editor ships with C# Roslyn Compiler - no need to install any external tools to compile and run C# code.
If you want to use custom .NET libraries use build scripts to reference them as shown here.
Flax supports native C++ scripting with direct access to whole engine API. C++ scripts can be created side-by-side with C# scripts and expose own types/functions/properties via automatic bindings as decscribed here. To write and use C++ code engine headers and platform toolset are requried.
To start native scripting in C++ see the related documentation here.
Flax supports Visual scripting with fully-featured Editor tools for creating, using and debugging Visual Scripts. Visual Scripts can inherit from C++ or C# classes (eg. custom Actor or Script) to provide more logic and data. Visual Scripting is very light-weight and extensible solution for prototyping games especially boosting the rapid development.
Visual Scripts can access to whole engine API and the game code. Visual Scripts can be created side-by-side with C# and C++ scripts to expose own functions/properties. Also, Visual Scripting doesn't requrie any additional tools nor compiler as it's hot-reloading in Editor without any processing to provide even more robust development.
To start visual scripting see the related documentation here.
- Create and use a script
- Script properties and fields
- Script events
- Accessing scene objects
- Creating and destroying objects
- Attributes
- Scripts debugging
- Visual Studio
- Visual Studio Code
- Scripts serialization
- Empty Actor
- Custom Editors
- Custom script editor
- Attributes
- Preprocessor variables
- Scripting restrictions
- C++ Scripting
- Visual Scripting
- Plugins
- Plugins Window
- Plugin Project
- Advanced
- Raw Data Asset
- Custom Editor Options
- Curve
- Access Game Window
- Multithreading
- Screenshots
- Gameplay Globals
- Tutorials
- How to create a custom editor
- How to create a custom editor window
- How to create a custom editor plugin
- How to create a custom asset type
- How to change scene from script
- How to use custom settings
- How to import asset from code
- How to control PostFx from code
- How to use third-party library
- How to add scripts module