Download

Implementing Item object as Actor class (Again Tick in Actor Component)

I have been resting for 1 week and ready to kick in Unreal Engine again.

I had a lot of problems during making very tiny demo… just TINY!

I underestimated the technical depth from Unreal Engine too much, even though I predicted it would be much harder.

Back to the question…

I already implemented base class of Item object as Actor class. The challenge I encounter is… sub type for Items.

There are weapon, ammo and goods (disposable). Yet few items has mixed use as weapon and ammo.

If I use inheritance, I have to make Weapon/Ammo class, which does not sound right for myself.

I thought about Actor Component as Item Type class. It sounds right for myself… kind of.

However I face another problem is that… if I ever need to use Tick Component in Actor Component… that’s different problem.

Since it is just Item, it won’t need tick a lot, but what if i need to use it? Then I feel scared about it, because

I tried to activate Tick Component in Actor Component for putting all character statistic such as current HP, but it failed to run Tick Component.

It is same question like my previous post…

How can I solve dis-enabled Tick in Actor Component? If I decided to use Item Type Object as Actor Component.

And is actor class okay for Item? it also images though.

Hi Marjane,

Welcome to the UE4 forum! Do not be afraid of the Tick function as many things will have to tick. Now to help answer your question, I think you should look into the attribute system built into Unreal. Sounds like you want to have a prop in the game affect something. Your prop ranges from consumables to weapons and perhaps range weapons? We can (and probably should) abstract their functions into “On use, affect something”. We can also abstract other actors with attributes such that your props apply GameplayEffects to them. Weapon is a little bit special because it also cares about collision and on hit, do damage (which is itself an effect that takes away the health attribute).

In short, your item actor should be a regular actor with a list of effects that will change one or more attributes on another actor. In this model, your item actor should not need Tick as their effects should only happen when an event has happened (on overlap or on use). However, if you need something dynamic like say the item changes color depending on the owner’s position, then you will have to Tick.

Does this make sense and help?

yes. It has been helpful. Since it is SinglePlayer, 2D JRPGs (Chrono Trigger, possibly old Final Fantasy), Weapons won’t contain collision check, yet still need to be adjusted into the unit (actor)'s hands and its statistic. Anyway. thank you so much for help. I may need to try to activate Tick in Item Class just like you said rather than with tick in actor component…in case if it has to be dynamic. Btw what is attribute system built into Unreal? I can google it, but do you have links or sample?

Mixed Use item is a Spear by the way, because it can be used as melee weapon, and as ammo by pipe gun. That’s the reason I implemented separate item type class such as Weapon (damage and durability), Ammo (Quantity and damage) and Goods (HP modifier and Quantity). I forgot to mention that in previous comment. But come to think of it… ChaoSXDemon… it would be better as sole actor with many variables. :stuck_out_tongue:

First check is to verify if the tick component is really running by having some sort of printout.



// actorcomponent.cpp  in constructor
		PrimaryComponentTick.bCanEverTick = true; // true if you need tick function.
		PrimaryComponentTick.bStartWithTickEnabled = false;  // self explanatory variable name 




// actorcomponent.cpp   in any other functions
SetComponentTickEnabled(true);  // or false to disable when you are done with tick function... 




// actorcomponent.h    you should have this by default
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;


I have tested tick functions to work with character, actor and actor component. The names might be different though.

Wow! thank you so much, when i get back to coding (tomorrow, i need to watch tutorials by my producer’s demand now), i will try your code.