Admittedly this is my first foray in to anything Unreal Engine related so it is entirely possible I have missed the functionality that meets my requirements. Or, perhaps there is a different way of achieving what I’m after?
I’m prototyping a music+puzzle game and want to see how far I can get without writing a single line of code.
I have a Blueprint, let’s call it “Puzzle Stage”, which defines some core functionality/behaviour and variables for Blueprints based on this.
Then each puzzle level is essentially a Blueprint based on that “Puzzle Stage” Blueprint. Each puzzle level has their own music files, camera components, artist/track details, timelines, etc.
Is there a way I can iterate all Blueprint classes derived from “Puzzle Stage” to get the artist/track strings, without actually instantiating that Blueprint Actor? (Presuming you can even treat blueprint variables as “static”)
Until I can work out a decent method for this I’m manually creating menu items/etc for each puzzle level Blueprint.
I suppose if there is a way to dynamically list levels in the game package I could change the structure so that a level is a puzzle…
Ultimately, if I have to manually define all menu items then I’ll have to do that, but it would be nice not to do that for every new puzzle/song that is added to the project.
Blueprints do support inheritance, and any blueprint derived from the base class does inherit all of the functionality from the parent class. It is also possible for child classes to override the default functionality. In order to create a child class, right click on the parent class in the content browser and select “Create Blueprint Using…”
As for iterating through the list, the answer is actually much easier than you might think.
Create a Struct for your Soundtrack information with whatever variables you want. Then, in your Puzzle Stage base class, create an array variable. Create the structs for each song, either procedurally or manually, and add them to the array.
After that, you can iterate through the array and perform whatever functions you want. Alternatively, you could create a class specifically for your music and put the functionality there. One small note though. To my knowledge you will not be able to act upon something that does not exist in your level unless it is added to your game mode class. So, if you want to act upon something that does not exist in the scene, that would be a good place to do it.
I did eventually work out a solution and forgot about this question altogether. The solution wasn’t as you explained, which is far more logical, but it suited the experiment at the time.
Your remark about Structs has given me a couple ideas for something unrelated as well.
Thanks for taking the time to answer, especially for such an old question! Much appreciated.
You are very welcome. Just make sure you know that you cannot (as of 4.5) set an element on a struct directly, you need to break the struct, make a new struct and relink the pins, and then set it to the proper array element.