Here’s that system- try to look past any grammatical errors, It’s late. Do ask any questions you have though.
AtomicSubsystem.h (4.8 KB)
You don’t need a .cpp for it, just the .h file. Unreal is sometimes funky with the generated cpp file though- you may need to create a GameInstanceSubsystem of the same name (AtomicSubsystem) first:
All you need to do to make it yours is to replace YETANOTHERTESTING_API
in
class YETANOTHERTESTING_API UAtomicSubsystem : public UGameInstanceSubsystem
to be your own project’s API name- that’ll be default. The name is just your project name in all caps followed by _API
.
Instructions on how to add types to it are at the top of the class. I’ve done my best to keep it simple, but you’ll need to do some copy pasting.
Keep in mind the identifiers are one name to one type per object. Meaning you can’t have an atomic bool “SomeVar” and an atomic int “SomeVar” in the same object. Doing this won’t crash anything, but it will throw an error and fail the get function if you attempt to get a value as a type the identifier isn’t.
You can however override a name. So if you set “SomeVar” to a bool and then set it to an integer, that will work just fine. That bool will be lost to the void, but you can read the integer just fine.
Of course this is all within the context of a single owner. You can have two identical identifiers with different types as long as you aren’t using the same owner.
Actually using the subsystem is really simple. From practically anywhere, add the atomic subsystem node. There’s only one of them- you don’t need to create it or anything.
From there, you can add, set, and remove atomics. I’ve only implemented bool float & integer, but it’s very easy to add more.
These are the types of nodes (set/get/remove)
The identifier is the unique name for a property. I strongly recommend making name variables so that you can just use those instead of writing the same identifier every time.
This identifier can be anything you can think of. Ie “BubblegumCounter”.
Equally as important is the Owner. I’ve made it default to self, but it can be any Actor. Just keep in mind that you can’t have duplicate identifiers with the same owner (unless you really know what you’re doing and it makes absolutely perfect sense).
Last things last: return values.
Every get has two return values: a value, and a return value. A bit unintuitive, I know. The value is the value of the variable- ie true/5.0/2. The return value is whether or not it succeeded. Same case with RemoveAtomic.
Get will fail if the identifier doesn’t exist on that owner or it isn’t the type you’re trying to get it as. RemoveAtomic will fail only if it doesn’t exist.