Best place for gameplay constants
I have a whole bunch of constant values for controlling gameplay (like costs of items etc). Where is the correct location to store these constants.
I initially thought it should be in the GameMode since they relate to the game rules and don't change. However, this makes accessing them quite inconvenient as you have to cast the
Another way that would also ensure they were run time constant would be to have a static pure function that just returns the relevant value.
What is the best practise when it comes to this?
asked Sep 28 '15 at 04:10 PM in Blueprint Scripting
I like to distribute balancing values into the objects where they are needed. Item costs into the base item blueprint, camera values into the camera blueprint, character values into the character blueprint, and so on.
At the same time, I don't like the hassle of having to edit so many files, so I make all balancing values configurable from outside the game. In UE, there are two ways to do this: Config files and Data Tables.
Config files are extremely useful for global values.
First you flag a variable as "Config" ...
and then you can add a line in the Config/DefaultEngine.ini that specifies your variable's default value:
where "/Game" means the "Content" folder, YourBlueprint is the name of the Blueprint containing the variable, and ContentBrowserPath stands for the path within the ContentBrowser to reach the Blueprint. YourVariable is the variable name and VariableValue its default value.
To make a change in a config file take effect, all you need to do is restart the editor.
Data tables are useful if you have a lot of objects that share a set of variables, but use different values, such as characters that all have different values for health, damage, armor; or weapons with range, ammunition count etc.
To define your values in a data table, you need to first setup a Blueprint struct containing the variables and an Excel sheet containing the same variable names as columns (but leaving the first column for the row names == object identifiers). You can then export your Excel file to csv and drag the csv file into the editor to create a data table for the struct you defined earlier.
You can then access each Data table row by a name identifier (for example the object name) and access its variables anywhere you need it.
Here's some further documentation on data tables:
To make a change in the csv file take effect, you need to reimport the data table (which is a simple button click).
This wasn't what you asked for, but I hope you find it helpful. :)
answered Sep 28 '15 at 07:39 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here