Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:toolworks:docs:apparatus:trait [2021/06/11 15:41] – created vladius | en:toolworks:docs:apparatus:trait [2022/06/07 10:53] (current) – Fix structure name. jispar | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Trait ====== | ====== Trait ====== | ||
- | 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> | ||
- | ==== Garbage Collection Notes ==== | + | You basically create a header ('' |
+ | #pragma once | ||
- | 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. | + | #include " |
+ | #include " | ||
- | Luckily, you can do it quite easily by referencing the same objects | + | /** |
+ | * The state of being moved with a certain | ||
+ | */ | ||
+ | USTRUCT(BlueprintType) | ||
+ | struct MY_API FMoving | ||
+ | { | ||
+ | GENERATED_BODY() | ||
- | Referencing other Subjects via Subject Handles is perfectly fine though | + | public: |
+ | |||
+ | UPROPERTY(BlueprintReadWrite, | ||
+ | float VelocityX = 0; | ||
+ | |||
+ | UPROPERTY(BlueprintReadWrite, | ||
+ | float VelocityY = 0; | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | You could omit the [[ue> | ||
+ | with the fields exposed like that you can now use '' | ||
+ | |||
+ | ==== Blueprint Workflow ==== | ||
+ | |||
+ | As basically every Unreal Engine's '' | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | 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: |