Glue:Reference:Files:LoadedAtRuntime

Introduction

The LoadedAtRuntime property can be used to tell Glue to not load a particular file when a given Screen or Entity is created. By default the LoadedAtRuntime property is set to true, which means that an instance of a runtime object for the given file will be created. For example, if a PNG file is added to Glue, then Glue will create a Texture2D instance. If a SCNX file is added, then Glue will create a Scene instance.

GlueLoadedAtRuntime.png

If this value is set to false, then Glue will not create an instance of an object for that file, nor will it automatically load the file. However, the file will still be part of the project, so you can load it and work with it in custom code.

Common Usage

There are a number of reasons to set LoadedAtRuntime to false.

Custom handling of a File

LoadedAtRuntime is often set if a file is to be used in a custom way. One of the most common uses of this feature is to load a SCNX file into a SpriteEditorScene to create custom Entities base off of the position of Sprites in the SCNX.

LoadedAtRuntime can be set to false in projects which load file formats which are not understood by Glue (such as custom audio, texture, or model formats).

Selectively loading content

You can use LoadedAtRuntime if you want to selectively load files at runtime. For example, you may add multiple files to a Screen, but only load one of them depending on the state of the game. However, we recommend using the LoadedOnlyWhenReferenced property.

LoadedAtRuntime=false vs. LoadedOnlyWhenReferenced=true

The LoadedAtRuntime and LoadedOnlyWhenReferenced properties may seem to do similar things, and you may be wondering when to use one vs. the other. This section will discuss why both properties exist and why to use them.

By default LoadedAtRuntime=true and LoadedOnlyWhenReferenced=false. This means that a file will always be loaded whenever its containing Screen/Entity is loaded.

LoadedOnlyWhenReferenced=true can be used to either delay the loading of a file, or not load it at all depending on certain conditions in your game. For example, a particular texture for a Sprite may not be used if the player does not pick to use that specific file type.

LoadedAtRuntime=false tells Glue that you want a particular file to be added to Visual Studio, and that the file should be available to your program at runtime, but only through the file system. Glue will not generate any code to load the file at all. This means that custom code is in charge of loading the file completely, and that custom code can decide what to load the file into.

For example, if Glue generates code to load a .achx file, then it must be loaded into an AnimationChainList. If LoadedAtRuntime is set to false, it can be loaded into a different type like AnimationChainListSave, or even loaded into a string or some other custom type.