|
1 | 1 | # ResourceComponentPlugin |
2 | 2 | Actor Component that can be used for various resources. Includes a modifiable Health component and a ready-made Health component with UI elements. |
| 3 | + |
| 4 | +Support: lych.assets@gmail.com |
| 5 | +If you need support for previous engine versions let me know! |
| 6 | + |
| 7 | +You can find the Marketplace page for this plugin here: https://www.unrealengine.com/marketplace/en-US/product/849a9f0fec7040b1b4cca2b5d26a2755 |
| 8 | + |
| 9 | +Installing the Plugin: |
| 10 | +Plugins purchased through the Unreal Engine Marketplace can be installed using the process on the following page: https://docs.unrealengine.com/5.0/en-US/working-with-plugins-in-unreal-engine/#installingpluginsfromtheunrealenginemarketplace |
| 11 | + |
| 12 | +Enabling the plugin can be done through the process outlined at the top of the above page. |
| 13 | + |
| 14 | +#Plugin Information: |
| 15 | +Plugin Modules (Type): |
| 16 | +ResourceCompPlugin(Runtime) |
| 17 | +Plugin Classes (Parent Class): |
| 18 | +ResourceComponentBase(Actor Component) |
| 19 | +HealthResource(ResourceComponentBase) |
| 20 | +HealthResourceWithUI(HealthResource) |
| 21 | +DamageModificationData(Primary Data Asset) |
| 22 | +ResourceFunctionLibrary(Blueprint Function Library) |
| 23 | +DamageTypeModificationInterface(Interface) |
| 24 | +Plugin Enums and Structs |
| 25 | +EResourcePercentType (enum) |
| 26 | +EHealthRegenEventType (enum | Not available to Blueprints) |
| 27 | +EIncomingDamageChannel (enum) |
| 28 | +EIncomingDamageModificationType(enum) |
| 29 | +EOverheadWidgetVisibility(enum) |
| 30 | +FIncomingDamageModification (struct) |
| 31 | +Supported Platforms: |
| 32 | +Win64 |
| 33 | + |
| 34 | +This document shows Blueprint exposed variables and functions. Classes have alternative virtual functions for C++ derivatives and the header files have comments. Blueprint friendly names are used. |
| 35 | + |
| 36 | +#Resource Component Base (Actor Component) |
| 37 | +\#include "Components/ResourceComponentBase.h" |
| 38 | + |
| 39 | +Dispatchers |
| 40 | +OnCurrentAmountChange(Float NewValue) |
| 41 | +Called when any change to Current Amount occurs. |
| 42 | +OnDrain(Float NewValue) |
| 43 | +Called when any Drain occurs. |
| 44 | +OnAdd(Float NewValue) |
| 45 | +Called when any Add occurs. |
| 46 | +OnFill |
| 47 | +Called when Add results in CurrentAmount meets MaximumAmount. |
| 48 | +OnEmpty |
| 49 | +Called when Drain results in CurrentAmount meets 0. |
| 50 | +OnRegenStart |
| 51 | +Called when Regeneration begins. (Immediately before the first RegenTick occurs.) |
| 52 | +OnRegenEnd |
| 53 | +Called when Regeneration ends, whether through fill or a new drain occurring. |
| 54 | +OnRegenTick(Float NewValue) |
| 55 | +Called on every tick Regen occurs. |
| 56 | + |
| 57 | +Variables |
| 58 | +Resource Name…………………………………………………………………….Name |
| 59 | +The name used to identify this resource. |
| 60 | +Max Amount………………………………………………………………………….Float |
| 61 | +The base maximum amount of this resource. |
| 62 | +Regen Amount……………………………………………………………………….Float |
| 63 | +How much resource is filled per regen tick. |
| 64 | +Regen Rate………………………………………………………………..…………Float |
| 65 | +How many regen ticks occur per second. |
| 66 | +Regen Delay…………………………………………………………………………Float |
| 67 | +The delay after draining the resource when regen begins. |
| 68 | +Additional Exhausted Delay...………………………………………………………Float |
| 69 | +This is added to RegenDelay if regen begins when CurrentAmount is 0. |
| 70 | +Regen After Depletion…….…………………………………………………………Bool |
| 71 | +If true the resource will generate even after depletion. Useful for renewable resources such as Stamina. |
| 72 | + |
| 73 | +Functions |
| 74 | +AddResource (Float AddAmount) |
| 75 | +Increases the resource by a certain amount. |
| 76 | +DrainResource (Float DrainAmount) |
| 77 | +Reduces the resource by a certain amount. |
| 78 | +AddResourceByPercent (Float AddPercent, EResourcePercentType PercentType) |
| 79 | +Increases the resource by a percent relative to the current value or max value. |
| 80 | +DrainResourceByPercent (Float DrainPercent, EResourcePercentType PercentType) |
| 81 | +Reduces the resource by a percent relative to the current value or max value. |
| 82 | + |
| 83 | +Float GetCurrentAmount() |
| 84 | +Gets the value of the current amount of resource. |
| 85 | +Float GetMaxAmount() |
| 86 | +Gets the value of the max amount of resource |
| 87 | +Float GetCurrentPercent() |
| 88 | +Returns a percent (0 - 1.0) available of the resource. |
| 89 | +Float GetTimeSinceLastDrain() |
| 90 | +Gets time in seconds since the last drain attempt. |
| 91 | +SetRegenAmount (Float NewRegenAmount) |
| 92 | +Modifies how much resource is filled per regen tick. |
| 93 | +SetRegenRate (Float NewRegenRate) |
| 94 | +Modifies the speed of regeneration. |
| 95 | +SetRegenDelay(Float NewRegenDelay) |
| 96 | +Modifies how long until regen begins after draining. |
| 97 | +SetAdditionalExhaustedDelay(Float NewValue) |
| 98 | +Modifies how long until regen begins after reaching 0. |
| 99 | +SetRegenAfterDepletion(Bool NewValue) |
| 100 | +Sets whether the resource regenerates at 0 resource. |
| 101 | +Bool GetCanBeDrained() |
| 102 | +Checks if the resource can be drained. |
| 103 | +SetCanBeDrained(Bool NewParam) |
| 104 | +Sets whether the resource can be drained. |
| 105 | + |
| 106 | +Notes |
| 107 | +Setting any of the Regen variables to an invalid amount, for example: RegenAmount, Rate, or Delay being negative will disable regeneration. |
| 108 | +Many variables have Get and Set functions that can be overridden. This is to allow for modifications to the resource, such as an increase upon leveling where you may override GetMaxAmount() as MaxAmount * Level. |
| 109 | +Dispatchers are called on all instances, but may be called prior to replication. Related functions have a float that provides the soon-to-be replicated value. It is highly recommended to use this output instead of GetCurrentAmount. |
| 110 | +Setting the Regen variables during runtime should not affect delays or ticks unless modified as such, and should continue regenerating with the modification. |
| 111 | + |
| 112 | +#Health Resource (Resource Component Base) |
| 113 | +\#include "Components/Health/HealthResource.h" |
| 114 | + |
| 115 | +Dispatchers |
| 116 | +OnGenericDamageTaken |
| 117 | +Called on ApplyDamage when Point or Radial is not used. |
| 118 | +OnPointDamageTaken |
| 119 | +Called on Point damage taken. |
| 120 | +HitLocation and BoneName were removed due to the max number of variables, but these are in the FHitResult. |
| 121 | +OnRadialDamageTaken |
| 122 | +Called on Radial damage taken. |
| 123 | +OnModificationDataAdded |
| 124 | +Called when a modification data is added. |
| 125 | +OnModificationAdded |
| 126 | +Called when a modification is added |
| 127 | +OnModificationRemoved |
| 128 | +Called when a modification is removed |
| 129 | + |
| 130 | +Variables |
| 131 | +Default Modification Data……………………………………...DamageModificationData |
| 132 | +A data asset that will be added on BeginPlay. |
| 133 | +If any were added to the initial ModificationRules array, these will be added afterwards. |
| 134 | +Modification Rules……….………………………FIncomingDamageModification<array> |
| 135 | +Modifications that will be considered when receiving damage. |
| 136 | +These modifications will be executed in array order. |
| 137 | +If the method Override_Health is used, then all other modifications are skipped. |
| 138 | +Last Damage Causer……….………………………………………………………Actor |
| 139 | +Last Actor that damaged the owning actor. |
| 140 | +Last Location Hit From…………………………………………………………….Vector |
| 141 | +Location where the last damage was taken from. |
| 142 | + |
| 143 | +Functions |
| 144 | +FIncomingDamageModifications<StructArray> GetCurrentModifications() |
| 145 | +Returns all current modifiers. |
| 146 | +Bool HasModifications() |
| 147 | +Returns true if this has any of the listed modifications. |
| 148 | +float GetDirection (Vector Direction, Rotator BaseRotation) |
| 149 | +Returns a float that dictates direction. This functionality was ripped from the Get Direction node seen in Animation Blueprints. |
| 150 | +float GetDirectionToLocation(Vector Location, Rotator BaseRotation) |
| 151 | +Alternative to GetDirection if you want to check against a location rather than a direction. |
| 152 | +float ModifyDamage(float damageReceived, EIncomingDamageChannel damageChannel, DamageType DamageType, Name boneName, Vector damageOrigin) |
| 153 | +Modifies the incoming damage based on current modifiers. If overridden without a parent node then functionality must be manually implemented. |
| 154 | +bool ModificationAcceptsDamageType(FIncomingDamageModification modification, DamageType damageType) |
| 155 | +Returns true if the damage type is utilized by the modifier. If no damage types are whitelisted, the modifier accepts all. |
| 156 | +GiveModifier(FIncomingDamageModification newModifier, int insertAt) |
| 157 | +Adds a modifier at the given index. If the index is -1 the modifier is added at the end. |
| 158 | +GiveModificationData(DamageModificationData modificationData, int beginInsertAt) |
| 159 | +Adds all modifiers from the data at the given index. If the index is -1 the modifiers are added at the end. |
| 160 | +RemoveModifier(Name modifierName) |
| 161 | +Removes all modifiers with this name |
| 162 | +BindDamageDelegates |
| 163 | +Used to override Bindings for OnGenericDamageTaken, OnPointDamageTaken, and OnRadialDamageTaken. Called at Beginplay. |
| 164 | + |
| 165 | +Notes |
| 166 | +If BindDamageDelegates is overridden without binding the 3 core dispatchers, the original functionality with modifications may be broken. OnGenericDamageTaken, OnPointDamageTaken, and OnRadialDamageTaken each are bound to a function that calculates damage based on the modifications. |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | +#Health Resource With UI (Health Resource) |
| 171 | +\#include "Components/Health/HealthResourceWithUI.h" |
| 172 | + |
| 173 | +Variables |
| 174 | +Enable Onscreen…………………………………………………………………....Bool |
| 175 | +Setting for how and when to show the on-screen widget and the overhead widget. |
| 176 | +Overhead Widget Settings….………………………EOverheadWidgetVisibility<enum> |
| 177 | +Setting for how and when to show the overhead widget. |
| 178 | +On Screen Widget Class……………………………………………User Widget<class> |
| 179 | +This class is used when creating the widget for the possessing player's UI. |
| 180 | +Overhead Widget Class………………………………………….…User Widget<class> |
| 181 | +This class is used for the character's overhead widget used in a WidgetComponent. |
| 182 | +Overhead Widget Material………………………………………….…Material Interface |
| 183 | +The material that will be applied to the overhead widget. |
| 184 | +Use World Space………………………………………………………………….…Bool |
| 185 | +The material that will be applied to the overhead widget. |
| 186 | +Draw Size………………………………………………………………………..Vector2D |
| 187 | +The draw size used for the overhead widget. |
| 188 | +See similar settings in the WidgetComponent class. |
| 189 | +Draw At Desired Size…………………………………………………………….…Bool |
| 190 | +If true, the Overhead Widget's draw size uses the widget’s desired size. |
| 191 | +See similar settings in the WidgetComponent class. |
| 192 | +Overhead Widget Offset………..…………………….……………………….Transform |
| 193 | +The offset that the Vector will be from the owning actor. |
| 194 | +Overhead Widget Component……………………….………………WidgetComponent |
| 195 | +The Widget Component that is attached to the owner. |
| 196 | +Overhead Widget……………………………………….……………………User Widget |
| 197 | +The User Widget used in the Overhead Widget Component. |
| 198 | +On Screen Widget…………………………………………………………...User Widget |
| 199 | +The User Widget that is placed on the owning player’s screen. |
| 200 | + |
| 201 | +Functions |
| 202 | +ChangeWidgetSettings(Bool UseOnscreen,OverheadWidgetVisibility UseOverhead) |
| 203 | +Returns all current modifiers. |
| 204 | + |
| 205 | +Notes |
| 206 | +Options explaining for Widget Settings: |
| 207 | +Overhead Disabled: The Overhead widget is never shown, but is created. |
| 208 | +Show Only On Possessed Player: The Overhead widget is only shown to the owning player. |
| 209 | +Show Only On Other: The Overhead widget is not shown to the owning player. |
| 210 | +Show On All: The Overhead widget is used on both the owning player and others. |
| 211 | + |
| 212 | +#Damage Modification Data (Primary Data Asset) |
| 213 | +\#include "Components/Health/HealthResourceWithUI.h" |
| 214 | + |
| 215 | +Variables |
| 216 | +Modifications……………………………………..FIncomingDamageModification<array> |
| 217 | +An array of the modifications housed in this Data Asset. |
| 218 | + |
| 219 | +Notes |
| 220 | +This data asset is used to keep collections of modifications or a single modification used in multiple instances. For example: Creating a new data asset that doubles damage from a bullet damage type can be created and easily applied to various actors. |
| 221 | + |
| 222 | +Resource Function Library(Blueprint Function Library) |
| 223 | +#include "ResourceFunctionLibrary.h" |
| 224 | + |
| 225 | +Functions |
| 226 | +ResourceComponentBase GetResourceFromActor(Actor actor,Name resourceName) |
| 227 | +Returns the first resource with the given name on the actor. |
| 228 | +ResourceComponentBase<array> GetAllResourcesFromActor(Actor actor) |
| 229 | +Returns all resources with the given name on the actor. |
| 230 | +ResourceComponentBase<array> GetResourceFromActors(Actor<array> actors, Name resourceName) |
| 231 | +Returns the first resource with the given name on each actor. |
| 232 | +ResourceComponentBase<array> GetAllResourcesFromActors(Actor<array> actors) |
| 233 | +Returns all resources with the given name on each actor. |
| 234 | +AddResourceToActor(Actor actor, Name resourceName, Float addAmount) |
| 235 | +Adds to the first resource with the given name on the actor. |
| 236 | +DrainResourceFromActor(Actor actor, Name resourceName, Float drainAmount) |
| 237 | +Drains from the first resource with the given name on the actor. |
| 238 | +AddResourcePercentToActor(Actor actor, Name resourceName, Float addPercent, EResourcePercentType percentType) |
| 239 | +Adds a percent to the first resource with the given name on the actor. |
| 240 | +DrainResourcePercentFromActor(Actor actor, Name resourceName, Float drainPercent, EResourcePercentType percentType) |
| 241 | +Drains a percent from the first resource with the given name on the actor. |
| 242 | +AddResourceToActors(Actor<array> actors, Name resourceName, Float amount) |
| 243 | +Adds to the first resource with the given name on each actor. |
| 244 | +DrainResourceFromActors(Actor<array> actors,Name resourceName,Float amount) |
| 245 | +Drains from the first resource with the given name on each actor. |
| 246 | +AddResourcePercentToActors(Actor<array>actors, Name resourceName, Float addPercent, EResourcePercentType percentType) |
| 247 | +Adds a percent to the first resource with the given name on each actor. |
| 248 | +DrainResourcePercentFromActors(Actor<array>actors, Name resourceName, Float drainPercent, EResourcePercentType percentType) |
| 249 | +Drains a percent from the first resource with the given name on each actor. |
| 250 | +HealthResource<array> GetActorHealthResources(Actor actor, Name<array> healthNameFilter) |
| 251 | +Returns all health resources with the filtered names. |
| 252 | +Bool ActorImplementsAnyModification(Actor actor, Name<array> modificationNames,Name<array> healthNameFilter) |
| 253 | +Checks if the actor implements the modification on the listed Health Resources. |
| 254 | +GiveModificationDataToActor(Actor<array> actors,Name resourceName,Float amount) |
| 255 | +Drains from the first resource with the given name on each actor. |
| 256 | +RemoveModificationFromActor(Actor actor,Name<array> modificationNames,Name<array> healthResourceNameFilter) |
| 257 | +Removes modification data to the filtered HealthResource components on the actor. |
| 258 | + |
| 259 | + |
| 260 | +Notes |
| 261 | +This was created for easy access to resources on various actors by only needing the resource name and the actor. |
| 262 | +Most of the functions in this library should only be called on the server. This does not include the getter functions. |
| 263 | + |
| 264 | +#Damage Type Modification Interface (Interface) |
| 265 | +\#include "Interfaces/DamageTypeModificationInterface.h" |
| 266 | + |
| 267 | +Functions |
| 268 | +Float ModifyDamage (Float incomingDamage, Actor damagedActor) |
| 269 | +Used on Damage Type classes to modify damage directly on the damage type. |
| 270 | +If the modification attempts to use this, but the damage time does not implement the interface, it will not apply the modification. |
| 271 | + |
| 272 | +Notes |
| 273 | +This functionality is constant and can really only change by creating a new DamageType that implements the interface. |
| 274 | + |
| 275 | +#Enums and Structs |
| 276 | +EResourcePercentType (enum) |
| 277 | +Current |
| 278 | +Maximum |
| 279 | +EHealthRegenEventType (enum | Not available to Blueprints) |
| 280 | +Tick |
| 281 | +Start |
| 282 | +End |
| 283 | +EIncomingDamageChannel (enum) |
| 284 | +AllChannels |
| 285 | +PointDamage |
| 286 | +RadialDamage |
| 287 | +GenericDamage |
| 288 | +EIncomingDamageModificationType(enum) |
| 289 | +Add_Damage |
| 290 | +Multiply_Damage |
| 291 | +Override_Damage |
| 292 | +Modify_From_DamageType |
| 293 | +EOverheadWidgetVisibility(enum) |
| 294 | +Overhead Disabled |
| 295 | +Show Only On Possessed Player |
| 296 | +Show Only On Others |
| 297 | +Show On All |
| 298 | +FIncomingDamageModification (struct) |
| 299 | +ModificationName…………………………………………………………..Name |
| 300 | +Name used to identify this rule for GiveModification and RemoveModification. |
| 301 | +DamageChannel………..……………………………EIncomingDamageChannel |
| 302 | +What damage type prompts this. |
| 303 | +ModificationType……………………………EIncomingDamageModificationType |
| 304 | +How this damage modification is handled. |
| 305 | +Magnitude…………………………………………………………………….Float |
| 306 | +How much this modifies the damage. |
| 307 | +WhitelistedBoneNames……………………………………………Name<array> |
| 308 | +The bone that received the damage must be included in this array if it is not empty. |
| 309 | +MaximumRange……………………………………………………………..Float |
| 310 | +The maximum distance the damage can be taken from for it to be modified. If this is less than or equal to 0 it is ignored. |
| 311 | +The distance is measured from the owning actor and the HitResult trace start(Point), radial damage origin(Radial), or damage causer location(Generic). |
| 312 | +Additional Notes |
| 313 | +When creating a new widget for the HealthResourceWithUI component, you can create a function with the name SetResourceComponent using a ResourceComponentBase input and the function will automatically be called when using it as an Onscreen Widget or Overhead Widget. |
| 314 | +The HealthResourceWithUI component is not as malleable as the Health or base Resource component. It is primarily made to be a quick “drag and drop” on an actor blueprint. |
| 315 | +If these components are not functioning correctly in multiplayer, make sure the owning actor has Replicates enabled. If you’re using the components on a mesh you simply placed in the world it will not immediately work as that is not Replicated. |
| 316 | +The components above will work on actors and their subclasses. Keep in mind certain functionality such as onscreen functions will not work unless they are placed on a controllable Pawn or Character. |
| 317 | +All variables in the Details panel will be in either of these three categories:Resource, Health, UI. The functions in the function library are in: Resource Function Library. |
| 318 | +Some variables cannot be set with a simple Set Variable node, but must use the related setter function. This is due to other functionality being required when setting these variables to make sure the entire component updates correctly. |
| 319 | +Currently all modifications are stackable. Adding 2 “weak to fire (x2 damage)” modifications will result in x4 damage. Meaning there are NO precautions when accidentally adding duplicates. Additionally, removing modifications by that name will remove ALL modifications with that name, so you are not able to only remove 1. While this can be worked around, explicit functionality to better support this will come at a later date. |
| 320 | +Using a Modification with the Type of Override Damage will stop any further modifications and revert any previous modifications making the incoming damage be the magnitude value. |
| 321 | + |
0 commit comments