WCGASCustomCostFormula
Purpose:
This is an abstract base class that allows you to create custom cost calculations for Souls-like attribute purchasing systems. Instead of using built-in cost formulas, you inherit from this class to implement your own unique pricing logic for attribute upgrades.
What It Does:
When you create a Blueprint or C++ child class and override the Calculate Cost For Purchase function, this system:
- Provides complete purchase context - current attribute value, total purchases made, the specific attribute being upgraded, the actor making the purchase, and the spending rule configuration
- Runs your custom pricing logic every time a player attempts to purchase an attribute upgrade or the UI needs to display the next cost
- Supports sophisticated designs - class-based multipliers (Warriors pay less for Strength), soft caps with exponential scaling after thresholds, level-gated pricing, diminishing returns, or any formula you can implement
- Integrates with spending rules - access to base costs, multipliers, and other configuration from your SpendingRule data
- Works with the purchase system to validate costs and deduct resources automatically
How It's Used:
- Create a Blueprint child class (e.g.,
BP_ClassBasedCostFormula) or C++ subclass
- Override
Calculate Cost For Purchase event/function
- Implement your custom logic using the Context parameter (which contains CurrentPurchaseCount, TotalPurchaseCount, Actor reference, SpendingRule data, AttributeTag)
- Assign your custom formula to your Leveling Rules Data Asset →
CustomCostFormula property (in Souls-like spending rules)
- The system automatically calls it whenever the UI updates or a purchase is attempted
Designer-Friendly Example:
You want a Warrior class to pay 50 XP per Strength upgrade but 200 XP per Intelligence upgrade, while a Mage has the opposite pricing. You also want costs to increase exponentially after 50 total attribute purchases (soul level). You:
- Create
BP_ClassBasedCostFormula inheriting from WCGASCustomCostFormula
- Override
Calculate Cost For Purchase and check Context.Actor for their class