Use this guide when you want to add custom gameplay behavior in C#.
Write a custom component when you need:
Create a component that rotates its entity:
using System.Numerics;
using FrinkyEngine.Core.ECS;
public class RotatorComponent : Component
{
public float Speed { get; set; } = 90f;
public override void Update(float dt)
{
Transform.LocalRotation *= Quaternion.CreateFromAxisAngle(
Vector3.UnitY,
Speed * (MathF.PI / 180f) * dt);
}
}
Then:
File -> Build Scripts or Ctrl+B.F5 and confirm the entity rotates..fproject.Ctrl+B.Your custom type appears in the Add Component menu after a successful build if it is:
publicComponentPublic read/write properties are serialized automatically and appear in the inspector.
Typical examples:
AssetReference and EntityReferenceThe most important callbacks are:
| Method | Use it for |
|---|---|
Awake |
one-time setup when the component is created |
Start |
scene-start initialization before first Update |
Update(float dt) |
per-frame gameplay logic |
LateUpdate(float dt) |
work that should happen after normal updates |
OnEnable / OnDisable |
activation changes |
OnDestroy |
cleanup |
OnTriggerEnter/Stay/Exit |
trigger overlaps |
OnCollisionEnter/Stay/Exit |
non-trigger physics collisions |
Custom components loaded from scenes and prefabs must have a public parameterless constructor.
Do not put required runtime setup in constructor parameters. Use Awake or Start instead.
Supported property shapes include:
| Type | Notes |
|---|---|
float, int, bool, string |
primitive types |
Vector2, Vector3, Quaternion |
System.Numerics types |
Color |
Raylib color |
| enums | serialized by name |
EntityReference |
links to entities in the scene |
AssetReference |
links to project assets |
FObject subclasses |
polymorphic serialized objects |
List<T> where T : FObject |
serialized lists of polymorphic objects |
Use inspector attributes when the default property rendering is not enough.
Most useful ones:
| Attribute | Use it for |
|---|---|
[InspectorLabel("Name")] |
friendlier inspector labels |
[InspectorRange(min, max, speed)] |
clamped numeric editing |
[InspectorTooltip("Text")] |
inline help |
[InspectorSection("Title")] |
grouping related fields |
[InspectorReadOnly] |
visible but not editable values |
[InspectorHidden] |
serialized values that should not draw |
[AssetFilter(AssetType)] |
narrowing an AssetReference picker |
[ComponentCategory("Path")] |
organizing the Add Component menu |
[ComponentDisplayName("Name")] |
custom component name in the editor |
public EntityReference Target { get; set; }
Use this when a component should track or talk to another entity. See Prefabs for remapping behavior.
[AssetFilter(AssetType.Prefab)]
public AssetReference ProjectilePrefab { get; set; }
Use this when designers should choose a prefab, sound, model, or other asset from the inspector.
Check these first:
publicComponent.fproject points to the correct game project and game assembly