Variable out of scope

hi i’m new to blueprint and ue4. I’ve set up this simple example to ask you i got variable out of scope:

I’ve created a blueprint actor class called “pickup”. From that class i’ve created 2 sub-classes called pickup_child_yellow/red.
I’ve set up the pickup’s construction script this way:
link:Pickup

I’ve created a mygame mode (left all default value) and i’ve set in the project setting this mode as default.
I’ve spawned 1 object of the blueprint’s subclasses in the level.
I set up the Construction script of Mygame mode:

link:MygameMode
and when i press play and i go to debug i’ve found out this:
link:Debug

sorry for my bad english, not my main language :(… hope to solve this problem.
Thank you for your help guys.

Moving the nodes from the Construction Script into the Main Event graph, and connecting them to Event Begin Play, should fix the issue. Basically, Construction Script shouldn’t be used for initialization, that should happen in Event Begin Play.

oh thank you, and what construction script is about ? something like setting meshes ?

You can do a lot of things in Construction Script; like, creating dynamic materials, scripting systems for laying out instanced meshes in a level, etc. The main thing to remember is that Construction Script only runs inside the editor, and not when the game is running.

ok yeah i had already experimented with dynamic materials but i taught i could also initialize variable, so i was wrong :stuck_out_tongue: … really thank you man, i tried out and it worked :slight_smile: thanks again.

@JonathanADaley “connecting them to Event Begin Play” sure this will allow you to debug and see the variable out of scopes value, but this is frustrating, we should be able to watch a variable’s value without having to connect it to a Print String or any other method

You can add variables to the Watch List by right-clicking on an output pin and selecting “Watch this value”:

But, I prefer to just put in a Print String, this way the value is not only printed in the Log, but can also appear on screen during PIE or in a Debug build. It’s personal preference as to which way is “best.”

I should also note though that you will still run into the “out of scope” issue when Watching a value, if that value is out of scope.