Access gameobject variable created with bolt in a prefab from script

Hi there! So I have these objects called Circle 1, Circle 2, Circle 3… (prefabs) and each one of them has a script and a flow machine with visual scripting.

In the visual scripting I created a Boolean and I want to access it from the script in the same object to check if it’s true.

I’ve followed these simple instructions

And the important part of the code is finally this:

var Negative = (bool)Variables.Object(Circle).Get("Negative");

        if (Negative){ return; }

Does not work this way because it gives me this error:

“The name ‘Circle’ does not exist in the current context”

So I solved it, like says in that link with the instructions, by adding at the beggining the object reference:

public GameObject Circle;

The error disappears but is not working. I supose it does not because the object name (that contains the script) is not only circle, they are prefabs, more than one in the scene, so one is circle 1, other circle 2, circle 3, etc.

The console error gives me this:

UnassignedReferenceException: The variable Circle of CircleController has not been assigned.
You probably need to assign the Circle variable of the CircleController script in the inspector.

Do you know a way to do that? Maybe telling the script to access the variable that is in the same object as the script? So sorry, I’m a game designer that started to study visual scripting and sometimes code seems like hieroglyph to me.

Can somebody help me? Thanks for your time and support!!

I’m sure this can be done. I just don’t know how, and you might not find a lot of folks here who do. The reason is we tend to be code weenies around here (I know I am!).

If you go up one level in the forum and look two groups down from Scripting (this group), you will find Visual Scripting and I bet people there can hook you up with precisely the right magic.

1 Like

Wow, you are completely right (not about you being a weenie ;)) that this is not the right place! Thank you for your answer!!

1 Like