Download

Functions/Inheritance for Blueprint Structs

This is half a request, half a question perhaps…since I’m not sure if I missed anything or whether it already works and I just couldn’t find it; but anyways, here goes:

For my April Game Jam submission, I built a feature that stores events (such as player movement) in an array and lets them rewind it (practically a rewind time effect).

First I made a prototype that simply used a BP Struct and 2 BP Functions - one to add items to an array, and another to replay them (sped up to give the rewind effect, plus clearing the array afterwards). This worked fairly fine, but even there I wished to have some way of putting the actual logic of rewinding a particular item inside the array into the item itself (practically, a method inside the BP Struct). Might be the software developer in me trying to do this, but lets continue for now.

When I made the actual game, I noticed the shortcomings of the prototype. It only recorded one type of action; player movement. But in the game, I had multiple actions that needed to be rewinded and possibly reversed (such as score, spawned/destroyed actors, and random stream seeds amongst others).
Each of them had different properties to be stored, and also had different actions to perform (one resets actor location, the other spawns/destroys an actor, etc).
First idea that came to mind was putting all fields into the struct, and adding an enumeration to indicate the type of action. But then again, the software developer in me screamed polymorphism…besides the fact that I didn’t want a big switch inside the rewind function.

Lastly, the actual implementation that made it into the game (as suggested by an older post on AnswerHub):
A base BP Actor with no components attached, some common variables and an empty Execute function (and a dummy Output variable, so it wouldn’t turn into an Event inside the derived BP). Create BPs derived from that which in turn implement the Execute method and do whatever is necessary. The software developer in me was satisfied…somewhat.
Drawback of this was that I had to spawn them as actors, and also destroy them if I didn’t need them anymore. Which was ok-ish, but still something to keep in mind when doing this.

So, to sum it up for the question/request part:
Is this the currently intended way to do this, or did I miss any features in 4.7 that would have helped here? Note that I do know of Blueprintable Components and I use them for the player movement/location tracking; but they didn’t really fit into the rest (at least I had some case where I thought it wouldn’t work…but I can’t really remember what that was).
And also: Is something like this even being considered for a future version of the engine? Data only Blueprints that contain Functions (similar to BP Libraries) and related variables (similar to BP Structs), but no world representation in terms of components/static meshes/etc. A Programmer would probably call them…Classes :slight_smile: