CResourceManager
Overview
UCResourceManager is a UGameInstanceSubsystem that manages a named resource inventory (resourceMap) and a mechanic object registry (mecanikMap). It implements ICResourceData and broadcasts onResourceEvent on every resource change. Registered as a singleton via CNAME_Singleton_ResourceManager.
Functions
| Name | Description |
|---|---|
| getInstance | Returns the UCResourceManager instance from a given actor’s game instance |
| countAny | Returns the quantity of a single named resource |
| countAll | Returns the summed quantity of multiple named resources (duplicates counted once) |
| removeAny | Removes a single named resource from the map and broadcasts |
| removeAll | Removes multiple named resources from the map and broadcasts |
| setupAny | Sets a single named resource to a given count and broadcasts |
| setupAll | Sets multiple named resources to a given count and broadcasts |
| consume | Decreases a resource by count, resolves its UClass from DataTable, broadcasts. Returns new stock |
| supply | Increases a resource by count, resolves its UClass from DataTable, broadcasts. Returns new stock |
| boundToOnResourceEvent | Binds an ICResourceBoundable listener to the onResourceEvent delegate |
| unboundToOnResourceEvent | Unbinds an ICResourceBoundable listener from the onResourceEvent delegate |
// getInstance — static, returns the subsystem from an actor's game instance
UCResourceManager* mgr = UCResourceManager::getInstance(myActor);
// countAny — returns the quantity of a single resource
float water = mgr->countAny(FName("Water"));
// countAll — returns the sum of multiple resources (duplicates counted once)
float total = mgr->countAll({FName("Water"), FName("Spice")});
// removeAny — removes a single resource entry
mgr->removeAny(FName("Water"));
// removeAll — removes multiple resource entries
mgr->removeAll({FName("Water"), FName("Spice")});
// setupAny — sets a resource to a given count (default 1.0)
mgr->setupAny(FName("Water"), 10.0);
// setupAll — sets multiple resources to the same count (default 1.0)
mgr->setupAll({FName("Water"), FName("Spice")}, 5.0);
// consume — decreases resource, returns new stock, resolves UClass
UClass* resourceClass = nullptr;
float newStock = mgr->consume(FName("Water"), resourceClass, 2.0);
// supply — increases resource, returns new stock, resolves UClass
float newStock2 = mgr->supply(FName("Spice"), resourceClass, 3.0);
// boundToOnResourceEvent — bind a listener
mgr->boundToOnResourceEvent(myBoundableObject);
// unboundToOnResourceEvent — unbind a listener
mgr->unboundToOnResourceEvent(myBoundableObject);