Hi Epic Staff,
Seems I ran into a bit of a problem scripting my blueprints and I was wondering if it’s because of some sort of bug.
Here’s the situation.
I have a blueprint called room that will check the level for any other blueprints of the type room since each needs to have its own ID.
So it uses a GetAllActorsOfClass node with class set to room and a ForEach loop to determine the other rooms’ ID value. After assigning itself an ID, it will go on with additional roombuilding functionality with local variables and such to create floortiles and whatnot.
Although placing multiple instances of room in the level seems to allow each to assign itself its own unique ID, it seems to clog up the rest of the blueprint (which is all in the Construction Script), making it seem as if the blueprint is somehow corrupt. Additionally, although one room in the level works fine, placing a second will make the first break, removing all functionality post-Room ID assignment.
I have figured out a solution to this problem and it is as can be seen in my screenshots.
Graph with function as solution - encapsulating the two room IDs in a function solves everything.
That’s it! That’s all there is to it. There’s not even one node changed from my previous setup. The only difference is that now, the RoomID variable native to the blueprint calling the script (the local instance of RoomID) and the RoomID residing inside the blueprint referenced by the ForEach loop are both inside a function together, separated from the rest of the graph.
Now I didn’t just invent this myself. I was reading online about similar problems and found that this is also the solutiokn to what you have to do when a variable is “not in scope”, generally the case when two blueprints need to communicate with each other.
First, I set this up using a Cast node, and that yielded the same functionality, i.e. fixed the problem. But the editor warned me a Cast was not necessary as the Array item was already referencing the specific actor room. So I put the two variables inside a function instead, no Cast involved, and it also solved the problem!
I suspect there’s something weird going on with variable scope. Putting these variables inside a separate function has effectively turned the function into a Getter, actively calling the values of the variables (correct?). I do not know why it breaks the functionality of the rest of the blueprint without this Getter, but it is mighty strange.
Hope you can figure out what this all means.