Loading a visual prefab during runtime — Addressables vs Resources
- Resources requires that my prefabs are in Assets/Resources. From there, it can access the files using something like Resources.Load<GameObject>(”VisualPrefabs/FireballVisual”);
- Addressables recommended for scalability as it’s designed to solve the limitations of Resources and support more complex workflows:
- Memory Management
- Resources keeps everything in memory unless manually unloaded
- Addressables let you load or unload asynchronously and only keep what you need
- Decoupled Content
- I can store assets in separate bundles and download them remotely
- Thus I can download one mod but leave another mod undownloaded despite being installed
- Better Build Control
- With Resources, everything in the Resources folder is bundled in the build, even if unused
- With Addressables, you can exclude unused assets more cleanly
- Labeling and Grouping
- Assets can be grouped and tagged
- This means I can manage large numbers of visual prefabs, clips, or so on cleaner and faster
Given this, it seems like I should use Addressables
Identifier for spells
- String
- E.g. “Fireball”
- Simple and nice to work with, and makes sense to developers
- The problem is, several modders can create the same name for a spell
- Guid
- E.g. c9d7f7be-10e9-453b-a7e2-1a648e4fc2c2
- Globally unique identifer so no collision
- Not very readable at all
- Integer/Long
- E.g. 4
- Simple and also nice to work with, easy to use in an array of spells
- Need to be careful about IDs to prevent conflicts and it’s easy to grab the wrong spell
- Composite Key
- E.g. “ChangJu’sFireball”
- Best if several pieces of information are required for uniqueness
- Can have conflicts if someone tried and I don’t pick good identifiers (e.g. “ChangJu + Fireball and ChangJ + uFireball”)
- Hashing
- E.g. Add all ascii values for a spell’s data
- Good for optimizing space without Guid overhead
- Small risk of collisions
Where is my ID being used?
- When I parse through JSON file and create the spell, I will also create the ID
- This ID will be distributed to several places:
- A map will hold ID as the key and the spell as the value
- Player spell slots will have a subset of the IDs
- Casting the spell requires passing the ID to get the prefab
It seems like my use for the ID is to pass it everywhere and get the spell prefab. The only times my spell should be passed is in helper or utility functions.
In this case, I should use Guid as the identifier and ensure I have utility functions to help debug when necessary.
Keybindings
- Well basically I want to ensure people can customize their keybindings (e.g. change from Q to Z)
- When I get around to it, I’ll have to change my keybindings to a custom class that will map from their keypress to the action