Torque3D
  • General
    • Welcome!
    • Features
    • Release Notes
      • Version 4.0.3
      • Version 4.0.2
      • Version 4.0.1
      • Version 4.0
      • Version 3.10.1
      • Version 3.10
      • Version 3.9
      • Version 3.8
      • Version 3.7
      • Version 3.6.2
      • Version 3.6.1
      • Version 3.6
  • Getting Started
    • Introduction
      • What's the Torque3D Engine?
    • Getting Familiar
      • Getting a Copy
        • Torque Project Manager
        • Downloading it Yourself
      • Getting Ready for Launch
        • Running Pre-Built Binaries
        • Building the Engine Yourself
      • Launching the Game
        • Opening the Example Level
        • Launching the Editors
      • Your First Game
        • Introduction To The Engine
        • The Module System
        • Creating an empty gamemode
        • Adding a Player
        • Adding a Coin
        • Adding a win-condition
        • Custom coin asset
        • Counting coins
        • Adding some effects
        • Supporting multiplayer
        • Adding a Scoreboard GUI
        • Keeping the scoreboard up-to-date
      • Deep Dive: BaseGame Directory Structure
    • Best Practices
    • Porting a Legacy Project
  • For Artists
    • Assets
      • What are Assets?
      • How to Create a New Asset
      • Working With Assets
      • Deep Dive: Creating a New Asset Type
    • Art
      • File Formats
      • 3D Art
        • Shape Specifications
        • Coordinates System
        • Mounting Shapes
        • Animation
        • Player Setup
        • Blender -> Torque3D Pipeline
      • 2D Art
        • Working with Adobe Substance
    • Animation
    • GUI
      • Loading and Initializing a GUI
      • Expanding a GUI via Script
      • How to Network GUIs
    • Materials
      • Material Mapping
      • Material Animation
    • Terrain
    • Shaders
    • Lighting
    • Audio
  • For Designers
    • Base Classes
      • SimObject
      • SimGroup
      • SceneObject
      • Scene
      • Datablocks
    • Game Classes
      • Creating an Object
      • Destroying an Object
      • Gameplay Scripting
        • Spawning an Object from Gameplay Code
    • Modules
      • What are Modules?
      • How to Create a New Module?
      • Making a Module do Things
      • Installing Existing Modules
        • Where to Get More Modules
    • Scenes and Levels
      • How to Create a New Level
      • How to Load a Level
        • Deep Dive: Level Loading Scripts
      • How to Edit Levels
        • Opening a Level in the Editor
        • Spawning Objects from the Asset Browser
        • Working with Scenes
        • Using SimGroups
        • Changing a Level's PostEffects
        • Deep Dive: LevelAsset Companion Files
    • Game Modes
      • Creating a New GameMode
      • Making a Level Use Your GameMode
      • Adding Gameplay Code to Your GameMode
    • AI
      • Navmesh
      • Objects
      • Scripting
    • Inputs
      • Inputs and Keybinds
        • ActionMap
        • Bind Functions
        • ActionMap Stack
    • Localization
    • Editors
      • Changing Editor Settings
      • World Editor
        • Scene Editor
        • ConvexShape Editor
        • Terrain Editor
        • Terrain Painter
        • Material Editor
        • Spline-Based Tools
          • Mesh Road Editor
          • River Editor
          • Decal Road Editor
        • Datablock Editor
        • Particle Editor
        • Decal Editor
        • Forest Editor
        • Navmesh Editor
        • Deep Dive: Creating Your Own Editor
        • Shape Editor
      • GUI Editor
        • Interface Details
  • For Programmers
    • Compiling the Engine
      • Setup Development Environment
        • SDK and Library Installation
        • Git
        • Cmake
        • Creating a Fork on Github
      • Create a Project
        • Creating a Project With CMake
        • Creating a Project With the Project Manager
      • Compiling
        • Compiling in Windows
        • Compiling in Linux
        • Compiling in MacOS
      • Building the Project Manager
    • Introduction
    • Code Style Guidelines
    • Expanding the Engine
      • Creating a New Object Class
      • Exposing Object Classes to Script
        • addProtectedField
      • Adding a New Library to the Engine
    • Major Components of the Engine
      • Core
        • Console
        • Platform
      • Audio
        • SFX
      • Rendering
        • GFX
        • Render Bins
      • Physics
        • Stock T3D Physics
        • Physics Wrapper
          • PhysX
          • Bullet
        • Classes
    • Rendering
    • Math
    • Networking
      • Client and Server Commands
    • Physics
    • Collision
    • Scripting
      • TorqueScript
        • What is TorqueScript?
        • Basic Syntax
        • Variables
        • Types
        • Operators
        • Control Structures
        • Functions
        • Objects
        • Module Interop
          • QueueExec
          • RegisterDatablock
          • CallOnModules
          • ModuleExec
        • API Reference
      • Other Languages
        • C-Interface
    • File Inputs/Outputs(I/O)
    • API Reference
Powered by GitBook
On this page
  • What is a Datablock?
  • Features of Datablocks
  • Using Datablocks
Edit on GitHub
Export as PDF
  1. For Designers
  2. Base Classes

Datablocks

In Torque3D, Datablocks are a way to store data that can be shared among multiple instances of a class. They allow you to define common properties and behaviors that can be shared by multiple objects, making it easier to manage and maintain your objects in a scene and minimizing data duplication and networking overhead.

What is a Datablock?

A Datablock is a type of object in Torque3D that stores data that can be shared by multiple instances of a class. They are defined as separate objects from the objects that use them, and they contain data that can be used by multiple instances of a class to define their properties and behaviors.

Features of Datablocks

Datablocks have several key features, including:

  • Reusability: Datablocks can be used by multiple instances of a class, which makes it easier to manage and maintain your objects in a scene. You can define a Datablock once, and then reuse it for multiple instances of a class, which saves time and reduces the risk of errors.

  • Flexibility: Datablocks can be changed, and the changes will be reflected in all instances of a class that use the Datablock. This allows you to make global changes to the properties and behaviors of objects in your gane, without having to make changes to each object individually.

  • Performance: By using Datablocks, you can reduce the amount of memory and processing power required to manage and maintain your objects in a scene.

  • Networking: Because Datablocks are sent from server to client, the game can be assured that the client has the same data as the server. Additionally, because they're sent during initial connection, it's data that doesn't need to be re-sent during normal network updates, keeping data transmission as low as possible.

Using Datablocks

To use a Datablock in Torque3D, you need to create a Datablock object and define its properties. Then, you can reference the Datablock from multiple instances of a class to share its properties and behaviors.

For example, let's say you have a Player class, it has a variable, health, that can be used for all instances of the Player class. To use this, you would create a PlayerDatablock object, and define the health property. Then, you would reference the PlayerDatablock from each instance of the Player class to share its health property.

datablock PlayerDatablock(PlayerDB)
{
   health = 100;
};

// Use the datablock for the player
%player = new Player() {
   datablock = PlayerDB;
};

In this example, the PlayerDatablock object is defined with a property named health, which is set to 100. The Player class references the PlayerDatablock by calling the setDatablock method and passing in the PlayerDB object.

For a breakdown of how to create your own classes utilizing datablocks, you can go to this page:

PreviousSceneNextGame Classes

Last updated 2 years ago