How do YOU do your inventory systems?

I’m just curious how everyone does this core mechanic that most games have. There’s so many ways, and I wonder how each solution impacts performance and if anyone has feedback to share.

The obvious ways are:

  1. Storing data in an array inside the character, functions in character to manipulate inventory.
  2. Create an ActorComponent that stores this data in an array + built in functions
  3. … ?

I used to do 1, now I do 2 because all the functions can follow the ActorComponent and I can add it to any Actor that needs an inventory (AI, bookshelf, chest, other characters, etc)

I wonder how the performance is impacted in option #2, by using functions of an actor nested in another actor. Thoughts? Other ideas?

In my project I use the 2nd method (Have the inventory as an actor component that can be attached to the actor).
As far as I know this has very little performance impact since there’s only 1 inventory and that is only on the player character. Obviously if you want to you can just overrides from UObject rather than from UActorComponent and that will save some memory.

When your inventory has its own functions instead of being just an array of items, it should be a separate class. Using an ActorComponent for an inventory is the best approach since you get more functionality from an ActorComponent than from a UObject.

> UActorComponent documentation

> UObject vs UActorComponent

1 Like

ActorComponent is not an actor, just a component (a scene component is an actor component itself, not to mix up with actor child component,which are just garbage) so it’s not that costy to use ^^

I don’t think you should worry about the performance cost of calling a method on a component versus on an actor itself.

There is virtually no difference in performance cost unless you’re doing something like FindComponentByClass every time you call a method on it.

Epic recommends that new games be done with a major focus on Components instead of by cramming a lot of code onto a few classes. The entire LyraStarterGame framework is set up with that design in mind.

They have an inventory system in Lyra, I haven’t had time to investigate it yet, but it might be worth looking into if you haven’t already built something. Their system purportedly demonstrates best practices so it’s worth being aware of.


Thanks for answering. It’s interesting you mention there’s almost no difference in performance. Is there more info on the do’s and don’ts of UE5? I’m used to programming in JS and have touched many languages, but not C++ that much. Not because I don’t like it or anything, but just because I want to avoid learning yet another language. I though I could do most of the stuff in Blueprint so stuck with that, avoiding the obvious “Event tick” and stuff like that, but after seeing this video or a simple for loop, I got pretty worried by the performance drop compared to C++. Since then I’m trying to be even more smart about blueprints lol. (granted the video is 5year+ old)

I meant that in C++ there is virtually no difference in calling a method on an actor versus on a component of that actor. Either way you’re dereferencing a pointer and invoking a method.

In C++ specifically the additional overhead comes from having to GetComponentByClass or whatever, so that should be kept to a reasonable minimum.

As for C++ vs Blueprints, there is definitely a difference. However, Blueprints aren’t really too bad in terms of performance since they’re ultimately C++ at a high level - scripting. You get some conveniences for scripting but you do lose out on some performance as a result of that convenience.

Even in Blueprints, if you cache the result of a GetComponentByClass then you can easily and relatively performantly invoke methods on the component just as effectively as on an actor.

Hey @xi57 , I was wondering if you ever got to look into that Lyra inventory ? It seems to be bugged and I have been attempting to sort it out with no success. Not sure its currently the best example as it seems to be incomplete. I have been trying to get a reply from someone who might know what the issue is , guessing will probably have to be a epic game dev. I made a post about it here Lyra Proto Inventory System & World Collectable Item Issues if you possibly have any input or even just an idea of Epic game devs I might be able to tag in the post to hopefully get a response ?

I haven’t yet made it to the inventory, I’m still learning all about Lyra style Gameplay Abilities/Cues/Tags.

I did briefly read through the Inventory h/cpp source and it seems like inventory is coupled to the abilities, so hopefully after I spend some more time learning this stuff the inventory system will be easier to understand.

1 Like

Still using Lyra’s base inventory and weapon system. The building blocks seem to be there and it’s like an ARC Inventory Lite. Having trouble trying to incorporate a combat component for melee hit detection. The ones I’ve used before, Combat Components and AGR both require a mesh attached to a character. I can’t think of a way to make this work with the current system.

There is a skeletal mesh attached to the character, but it’s invisible. The visible mesh is attached to a sub-actor that gets assigned on spawn. Not sure if both have collision enabled, I haven’t really done much with collision yet.

Oh yeah the character is fine. I mean, those Components require a Weapon Mesh be given to the character. So perhaps I can intercept that to use the one Lyra applies when an active weapon is equipped.

Ended up making a WaitForEvent Task for Lyra to try to pass the active SK to the GA. Will see how it goes once I can fix the compile issue. Some obj reference is going on. I noticed it doesn’t seem Lyra made any Lyra specific tasks, only references the vanilla GAS ones.

Following up on this thread as I recently did a deep dive into Lyra’s Inventory, Equipment and Weapon Systems.

My write-up RE Inventory System:

And in Video form: