Getter node necessary to avoid scope problem?

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.

However.

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.

Function

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.

Thanks,
Shrooblord

Hi Shrooblord,

I just want to make sure I fully understand what you are saying so that I can reproduce this effectively. Your getter function, which simply takes the room ID variable from the “get all actors of class” node and compares it to the room ID var of the blueprint in question, does not work in the main event graph. It only works if you have it separated out into its own function?

Yes, that is the case. If the getters are in the main event graph, the rest of the construction script does not execute.

Do any specific errors appear on screen or in the output log when you attempt this without the custom function?

The only thing I’ve been able to debug in this is that the RoomID of ForEachLoop blueprints are “Not in Scope” when tracked with Watch this Value.

Can you send me a sample project that is experiencing this error? I’d be happy to take a look and see what may be occurring.

Hi Shrooblord,

We have not heard from you in several days. I am marking this thread as answered for tracking purposes. If you are still experiencing this error, please comment back with the requested information.

Sorry about that. Haven’t found the time to recreate the problem in a sample project. Will do this in the next couple of days. Can I find you on the forum and send a project to you there, or should I post a download link here?

It would be best to post it here if possible. If privacy is a concern, however, you can send it to me in a private message on the forums (same user name).