Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.


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. Graph with function as solution - encapsulating the two room IDs in a function solves everything.

Function 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

Product Version: UE 4.9
more ▼

asked Sep 12 '15 at 03:40 PM in Bug Reports

avatar image

91 18 20 21

avatar image Adam Davis STAFF Sep 14 '15 at 05:55 PM

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?

avatar image Shrooblord Sep 18 '15 at 07:32 AM

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

avatar image Adam Davis STAFF Sep 18 '15 at 03:04 PM

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

avatar image Shrooblord Sep 18 '15 at 09:01 PM

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.

avatar image Adam Davis STAFF Sep 21 '15 at 05:45 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Sep 25 '15 at 08:30 PM

avatar image Shrooblord Oct 03 '15 at 11:12 PM

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?

avatar image Adam Davis STAFF Oct 05 '15 at 03:06 PM

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).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question