When I try to access variable in blueprints, it always evaluates as false. I added it through cpp and set it up in instance of actors (like editable blueprint variables)
I’m not setting it anywhere as far asI can see. I added it to the BT service now and in debug window I notcied that it irregulary and very often changes from true to false and then to true again
You have to set a variable in the constructor if you do not want to experience undefined behaviour. The variable is empty and has no value set so it can be anything. The code you showed is fine, but there has to be more. Where is it exposed? Where is it used? Every time an object containing this variable is created the value of that variable is random. It can be true OR false. That means that every time it you spawn one, every time you restart the simulation or play in editor it is randomized. In the constructor set the variable to true or false and the problem should be fixed.
Then my only advice is to recreate a small test project with your variable in it and see if it changes. It is highly weird that you have this behaviour. Are you sure you are not overriding the constructor without calling the super constructor?
Can you explain or provide a screen shot of where you’re using the boolean value? If the boolean is always returning false, there may be something wrong with the setup that switches the value of the variable as necessary.
I tried creating a bool in code and printed it from a blueprint as shown.
Hey, I’m declaring it in my custom enemy Character class, initialize it with false in constructor, then set it up for instances of those enemies in editor. I need it in Behaviour Tree to establish if I should go down one branch of it. It didn’t work so I put it to service to check if maybe it will set up correctly at later time. It didn’t so I added it to print string of EventTick of my enemy Character and it alternates between true and false. The only times I set it up is in the constructor and the checkbox on Character instances
That was it, thanks! I can’t remember setting it up earlier, was it added at later time? Also I think it would be quite more intuitive for this to be false at default (or is there something I don’t see here?)