# Using Runtime Types as Objects

### Introduction

Objects can be instantiated directly inside the Objects folder of Screens or Entities. Typically these instances are of standard types such as Sprite or TileShapeCollection. Also, the type of instances can be entity types, such as an instance of a Player in the GameScreen. If your game includes a special type which is not an entity type, the FlatRedBall Editor can display this type by adding it to a custom type CSV.

### Example - Instantiating a Custom PositionedObject

As an example, consider a custom PositionedObject class. The class doesn't need to have any functionality, it just needs to be defined in your project so that generated code can work with it. Therefore, an empty class will do, as shown in the following snippet:

```
using FlatRedBall;

namespace CustomTypeProject
{
    public class CustomType : PositionedObject { }
}
```

Now we can add this type to a custom CSV.

1. Select **Content** -> **Additional Content** -> **New Content CSV...**

   ![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-9ba41de5e01966d828c7f433d81f5abaf9e6751e%2F2023-05-img_645d6d3eb725a.png?alt=media)
2. Enter the name ProjectSpecificContent and click OK

   ![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-0741109597c79b77be936ebd7a42c9c72946b1df%2F2023-05-img_645d6d7b58eb4.png?alt=media)
3. A folder should open displaying the newly-created ProjectSpecificContent.csv. Double-click it to open it in the default spreadsheet application installed on your machine

   ![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-18df0f84e06a96f0e1a6903bf7da55d057f1904a%2F2023-05-img_645d6dc7d1061.png?alt=media)
4. Enter the values for properties as specified below:

* Friendly Name: **CustomType**
* CanBeObject: **true**
* QualifiedRuntimeTypeName: **QualifiedType = CustomTypeProject.CustomType** (this should be your qualified name)
* AddToManagersMethod: **FlatRedBall.SpriteManager.AddPositionedObject(this)**
* DestroyMethod: **FlatRedBall.SpriteManager.RemovePositionedObject(this)**
* ShouldAttach: **true**
* IsPositionedObject: **true**
* AdjustRelativeZ: **this.RelativeZ += value**

For examples on how to work with this CSV file, see the ContentTypes.csv file which is located relative to the GlueFormsCore.exe project, or in the Visual Studio project if you are building from source. Once you have modified and saved the CSV, shut down and restart the FlatRedBall Editor. If the file was loaded correctly you will see output which looks similar to the following text:

```
4:43:31.7 - Loading content types from C:/Users/vchel/Documents/FlatRedBallProjects/CustomTypeProject/CustomTypeProject/GlueSettings/ProjectSpecificContent.csv and found 1 types
4:43:31.7 - Adding 1 content types
```

You can now right-click on the Objects under any Screen or Entity and you should see your type.

![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-f3e5708ef594a3533ced6e2ad73891d442df1c0d%2F2023-05-img_645d6ff53da86.png?alt=media)

Since this type is also a PositionedObject, your entities can use it as their base.

![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-fb0d6149879927f2efd82e9a62be452e9995a0a7%2F2023-05-img_645d703ba763d.png?alt=media)

### VariableDefinitions

By default instances of new types that you create do not have any variables visible in the Variables tab. You can change this by adding variables which you would like automatically visible by modifying the VariableDefinitions column. The standard ContentTypes.csv file provides a great example of how to define VariableDefinitions. One of the largest set of variables is on the Sprite's VariableDefinitions column.

![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-d492578124bdcff23b379846160cf47c635a4a2c%2F2023-05-img_645d711051472.png?alt=media)

Add as many variables as you would like available. Also, you are not limited to PositionedObject properties. If you add new properties to your type in code, you can expose these to the FlatRedBall Editor by modifying the VariableDefinitions column.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/glue-reference/menu/content/glue-reference-menu-additional-new-csv/creating-runtime-objects-as-instances.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
