Disclaimer: This kind of spans across both C++ and blueprint domains. But I do believe here is the “more correct” place to post this.
I have been trying to figure out how a system of mine could be designed before I actually start coding it, and now I’m wondering a bit about how it would work with blueprints. I think some background is needed before the main question comes:
Let’s say I have a base item class called Item from which all game items are created. In a nutshell, the idea is to create items via a “bridge” to a data source, either an XML file or a database or something entirely different. The point is that the concrete implementations for different item types (let’s use Weapon and QuestItem for this example) are hidden from the rest of the game, which is really only interested in the interface. The items would likely be created by asking the bridge “Can you please give me an item with ID 48?” which then instantiates an item of the correct type (because it knows from the data source what type the item should be, and therefore the concrete implementation).
Now, making a blueprint of Item would be nice so that one could easily place various items in the world. The actual item would be determined by setting the ID property. This is where a problem arises:
The placed items are of type Item. While this is not a problem in itself, what happens when I want to select exactly which item it is? Let’s say I want the item to be of ID 48, which could be a sword or some other weapon. Now I’d like the construction script to make the item of the correct type (Weapon) using the bridge as outlined above. Maybe later I would change my mind and change the ID to 352 to have the item be “Sheldon’s magic pen keeper” which would require changing the item to a QuestItem. Is it possible to have the construction script change the type of the item like this? (I’m not talking about changing a variable telling the type of item, I mean the actual class it’s made of)