More Efficient Way That a Bunch of Booleans?

I’m trying to create a cozy farm game with a little more focus on the health and safety of animals and such, and I want various status effects for these animals (starving, dehydrated, overheating, etc.). The immediate and probably noob way of doing this would to create a bool for each one, then just flip the bool when the game wants to add it to the creature. This is obviously not very cost efficient, and I know that there has to be better ways, but I am absolutely blanking right now.

I have an animal base class, I have a status effect base class, and I just want to check for when a certain animal is supposed to be affected by a certain effect so I can apply the status effect to the animal. Any thoughts?

EDIT: I also need this to be expandable. I only have 3 animals and a handful of effects now, but I expect I will expand later.

Look into data assets
do something like this in your cow bp make sure to never edit the data asset itself its more for doing the calculations type thing

It can be specific to all cows or all animals depending which data asset you use as the input variable
either way you’ll end up with booleans but you won’t have to define things that are the same on each animal

also unless you have like 100s of thousands or so of bools your fine a bool is represented with 1 bit

so 1024 Booleans would use 1mb of memory :slight_smile:

Theres more complex ways to use data assets than what i showed above if you get into it
Also there’s data tables that work similarly but different but you’d likely have to figure out structures too…

You can also use these with a thing called structures which might technically be the answer to your question

1 Like

The most memory efficient way would be a flag based approach, maybe through an enum bitmask, but not sure if that’s fully doable in blueprint

I would suggest looking into gameplay tags, and give each animal a gameplay tag container, and add a tag for each status
You can then query the container very easy to see if a status is active
This is also a very easily expandable and readable way to go about it

After further thinking about it, I realized that I also am going to want things such as “hunger level”, “thirst level”, etc. as part of the animals, which would definitely be floats instead of bools. Due to this, structs may be the most efficient way to go about achieving this then, as those stats will also be universal. Thank you for the information! It’s greatly appreciated!

Gameplay tags sound like a great idea, actually. How would that compare to having a “AnimalStats” instance editable struct that the individual blueprints can call on?

I would say with tags you can have a more generic approach, and not rely on hardcoded members of a struct
But if you do make a struct that holds the different stats like you said, you can still give it a tag container to hold the status, and then work with that container when adding a status or when querying if the animal has a status

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.