Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:toolworks:docs:apparatus:trait [2021/06/14 18:29] – [Trait] jispar | en:toolworks:docs:apparatus:trait [2022/06/07 10:53] (current) – Fix structure name. jispar | ||
---|---|---|---|
Line 2: | Line 2: | ||
Traits are low-level data blocks (components) comprising subjects. Unlike [[en: | Traits are low-level data blocks (components) comprising subjects. Unlike [[en: | ||
+ | |||
+ | ===== Changing Traits ===== | ||
+ | |||
+ | The Trait data is what called value-type in some languages. The behavior is somewhat native for UE environment. This basically means that in order to change a Trait' | ||
+ | |||
+ | ===== Garbage Collection Notes ===== | ||
+ | |||
+ | As it was already said earlier Apparatus uses its own low-level memory model to store Traits efficiently. This comes at a certain cost. Basically you have to manually guarantee the safety for references to other UObjects (Actors, Components, etc) within your Traits, since those should be refernce-counted by the Garbage Collector which is absent. | ||
+ | |||
+ | Luckily, you can do it quite easily by referencing the same objects a certain asset or object via some global GC-managed UObject instance and retaining them this way. This global object may also be [[ue> | ||
+ | |||
+ | Referencing other Subjects via Subject Handles is perfectly fine though and is managed by Apparatus itself. Only remember that those Handles are like weak references. They don't hold the Subject referenced, they just invalidate themselves when the Subject is destroyed (despawned). | ||
===== Creating Traits ===== | ===== Creating Traits ===== | ||
Line 11: | Line 23: | ||
You should mainly refer to the official Unreal Engine manual on creating [[ue> | You should mainly refer to the official Unreal Engine manual on creating [[ue> | ||
- | You basically create a header (.h) file and optionally a source (.cpp) file. An example of such header-only Trait would be:<code cpp> | + | You basically create a header ('' |
- | // Fill out your copyright notice in the Description page of Project Settings. | + | |
#pragma once | #pragma once | ||
#include " | #include " | ||
- | #include "MyTrait.generated.h" | + | #include "Moving.generated.h" |
/** | /** | ||
- | | + | |
*/ | */ | ||
USTRUCT(BlueprintType) | USTRUCT(BlueprintType) | ||
- | struct MY_API | + | struct MY_API |
{ | { | ||
GENERATED_BODY() | GENERATED_BODY() | ||
Line 38: | Line 48: | ||
You could omit the [[ue> | You could omit the [[ue> | ||
- | with the fields exposed like that you can now use '' | + | with the fields exposed like that you can now use '' |
- | ==== Garbage Collection Notes ==== | + | ==== Blueprint Workflow |
- | As it was already said earlier Apparatus uses its own low-level memory model to store Traits efficiently. This comes at a certain cost. Basically you have to manually guarantee the safety for references to other UObjects (Actors, Components, etc) within your Traits, since those should be refernce-counted by the Garbage Collector which is absent. | + | As basically every Unreal Engine' |
- | Luckily, you can do it quite easily by referencing the same objects a certain asset or object via some global GC-managed UObject instance and retaining them this way. This global object may also be [[ue> | + | {{ : |
- | Referencing other Subjects via Subject Handles is perfectly fine though and is managed by Apparatus itself. Only remember | + | This will create a new asset file right inside the designated folder. You should give it an appropriate name after that. |
+ | |||
+ | {{ : | ||
+ | That's basically it and from now on the created structure can be used right inside your [[en: |