Skip to content

Commit 38c100f

Browse files
authored
Create creating-entities.md
1 parent f0a2518 commit 38c100f

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

docs/entities/creating-entities.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
layout: default
3+
title: Creating Entities
4+
nav_order: 2
5+
parent: Entities
6+
---
7+
8+
# Creating Entity Resources
9+
10+
In Qodot, you define new types of entities by creating a new .tres resource file. Qodot provides 3 resource presets for this:
11+
12+
- QodotFGDPointClass
13+
- QodotFGDSolidClass
14+
- QodotFGDBaseClass
15+
16+
Click the "New Resource" icon in the Inspector:
17+
18+
![](../images/res-inspector.png)
19+
20+
Or right-click the FileSystem and click "Create New Resource":
21+
22+
![](../images/res-filesystem.png)
23+
24+
Either will take you to the resource search screen. Here you can type in the following quick terms to narrow down the type of resource you want to create:
25+
26+
- pointclass
27+
- solidclass
28+
- baseclass
29+
30+
# Point and Class Resource Properties
31+
32+
These properties are shared by Point and Solid classes.
33+
34+
**Classname** - The name for this class in Trenchbroom.
35+
36+
**Description** - A short description that displays in Trenchbroom when this entity is selected.
37+
38+
**Qodot Internal** - Hides the entity in Trenchbroom's entity browser.
39+
40+
Qodot can still refer to this entity for building other entities (like base entities). Base Entities are already hidden in Trenchbroom by default, for most situations you can leave this off.
41+
42+
**Base Classes** - An array of template entities to inherit properties from.
43+
44+
This determines the parent entities for this class, where this entity gets all the class properties, meta properties, and property descriptions from its parents.
45+
46+
**Class Properties** - A dictionary of properties.
47+
48+
Once exported to the Trenchbroom game config, the dictionary values are written by editing entities in Trenchbroom, and read by accessing `properties` on a QodotEntity once the map is built.
49+
50+
To add a new class property to an entity:
51+
52+
1. Open the dictionary.
53+
2. Click the first pencil by "New Key: [null]" and select "String" as the key data type.
54+
3. Name your property in the key text field, no spaces.
55+
4. Click the second pencil by "New Value: [null]".
56+
5. Select any valid data type. Read [Class Property Data Types](#class-property-data-types) for more information.
57+
6. Change the value to your desired default, or leave it blank.
58+
7. Click "Add new key/value pair".
59+
8. Re-export your FGD once all class properties are added.
60+
61+
You can also set default values for your properties, by repeating this process in Meta Properties, matching the key names and value datatypes from this dictionary.
62+
63+
**Class Property Descriptions** - A dictionary of descriptions for each property, visible in Trenchbroom.
64+
65+
Follow the same steps as adding class properties to add property descriptions. Ensure the description's key matches the property's key. Description values can only be strings.
66+
67+
**Meta Properties** - Editor-specific properties, such as the default color and size used to represent this class.
68+
69+
Add an entry with a matching key to an existing property, set the value to the same data type, and whatever value is present will become the default. Only one meta property is read per class property.
70+
71+
**Node Class** - The type of Godot node to spawn at this location.
72+
73+
This doesn't fully control the type of node that Godot spawns, read on to learn more about using Node Class with Point Classes and Solid Classes.
74+
75+
## Point Class properties
76+
77+
Point Classes inherit all features from Base Classes, with a few additions. QodotMap reads their position in the map, and places a QodotEntity node in their place. You have the option to replace the QodotEntity node with other node types, or even instance .tscn scenes in their place.
78+
79+
**Scene File** - The .tscn Godot scene that spawns in place of QodotEntity. The easiest way to spawn a specific node at a specific point.
80+
81+
Scene File takes priority over every other option here, especially if there's already a script attached to the .tscn file.
82+
83+
**Script Class** - The script to attach to your entity's root node.
84+
85+
This is ideal for spawning nodes without a .tscn file. If you want to access this entities' Class Properties, add a script here that `extends QodotMap` and accesses `properties["key_name"]`.
86+
87+
You can extend other Spatial-derived node types too, and add necessary children (CollisionShape, MeshInstance) through code, but you lose out on the ablity to access `properties`. You can fix this by always choosing to extend `QodotEntity` and adding more complex nodes like Area and RigidBody as children through code.
88+
89+
Make sure to update Node Class so it matches the the script's `extends`!
90+
91+
**Node Class** - The type of node to spawn at this location. This property should match the `extends` of your Script Class. You can ignore this property if you're using a Scene File.
92+
93+
With those properties covered, there's a few tricks you can use to get more specific results.
94+
95+
If you want to create an RigidBody node without a .tscn using a point entity, extending `RigidBody` in thes script prevents you from accessing the class property values set in Trenchbroom. However, extending `QodotEntity` prevents you from accessing the functions and signals of a RigidBody.
96+
97+
You can get around this by extending `QodotEntity` and using `var body = RigidBody.new()` and `add_child(body)` to add more complex nodes as children, while still having access to the `properties` dictionary. This can be repeated for other children like MeshInstance and CollisionShape.
98+
99+
## Solid Class Properties
100+
101+
Solid classes can have multiple brushes, so these properties apply to the solid class as a single object, not to each brush individually.
102+
103+
**Spawn Type** - Changes how the QodotMap arranges these brushes in its node hierarchy.
104+
105+
There are 4 settings:
106+
- Worldspawn
107+
- Merge Worldspawn
108+
- Entity
109+
- Group
110+
111+
**Build Visuals** - Makes the solid class visible when checked.
112+
113+
You may want to disable this for invisible triggers and other gameplay-related solid classes.
114+
115+
**Node Class** - Sets the node type of the solid class root.
116+
117+
If you're adding a Script Class, this value should match the `extends` of the script.
118+
119+
Setting this to RigidBody and setting Spawn Type to Entity changes these brushes from static geometry into physics objects.
120+
121+
**Collision Shape Type** - Changes how collision is built.
122+
123+
- None
124+
- Convex
125+
- Concave
126+
127+
Convex creations a CollisionShape for each brush, depending on the Spawn Type. Entity creates an outer hull, Group creates individual shapes for each brush. Convex is a good bet for most situations.
128+
129+
Concave allows for concave brush geometry, or if you chose Entity and want a single concave CollisionShape to make up your solid class. 🚧
130+
131+
**Script Class** - The script applied to the entity's root.
132+
133+
Although `QodotFGDSolidClass` is a class you can extend from, this is meant as a Qodot internal to build solid classes. This does not extend QodotEntity, and will not give you access to `properties`.
134+
135+
# Class Property Data Types
136+
137+
As shown earlier in this page, you can define properties for entities in the Class Properties dictionary. The "key" for each dictionary entry should be a String. The "value" can only be one of these 8 data types:
138+
139+
- Bool
140+
- Int
141+
- Float
142+
- String
143+
- Vector3
144+
- Stored as a string in the form X Y Z
145+
- Color
146+
- Stored as a string in the form R G B
147+
- Dictionary
148+
- Used for defining a set of choice key strings and their associated values
149+
- Will display a dropdown in compatible editors
150+
- Available Dictionary value types haven't been thoroughly tested
151+
- Array
152+
- Used for bitmask flag properties
153+
- Will display a grid of checkboxes in Trenchbroom
154+
- Used in Quake to indicate which entities spawn on different difficulties - easy, medium, hard
155+
- Each entry in the array should be an array, with three elements: `[name: String, value: bool/float/int/String, default: same type as value]`
156+
157+
## Note on Arrays
158+
159+
When you add an Array as a class property, it must contain other Arrays, with each Array creating one flag. These flag Arrays must have 3 items: Name, Value, and Default value.
160+
161+
Name must be a String.
162+
163+
Value is traditionally a bool, but it can also be a float, int, or String. Qodot parses all these data types as Strings in the end, which will change how you will be [Accessing Class Properties in Code](#accessing-class-properties-in-code).
164+
165+
The default value can be the previous data type, or even `null`. It is not read by Qodot, just the regular Value.
166+
167+
# Accessing Class Properties in Code
168+
169+
See [Scripting Entities](scripting-entities.md).

0 commit comments

Comments
 (0)