Using Null coalesce to determine if an input value is provided?

Nathan Baune 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 3

Hello, I am trying to set up a super unit where if a Vector3 input is routed into the flow graph then it is used, if it isn't provided (nothing plugged into that value input) then use something else (in this case the 'self' transform.position). I attempted this using null coalesce, though it throws an error saying nothing is plugged into the "Position" input. If nothing is plugged in, wouldn't it spit out a null?

I was hoping to have highly reusable super units with minimal inputs. I often use 'self' values, though may want to use the same graphs with other inputs. I can solve this problem by including a bool input and a select unit, though in that case I would need an additional bool for every input that I want to behave in this way, which is sort of cumbersome. That is what I did in the super unit "Random Point Around Position" seen in the first image below.

Is there a way to accomplish this if null coalesce won't suffice?

Thank you, and thanks in general for Bolt. It is so professional (dare I say... beautiful) and has made creating complex systems and behaviors relatively painless---often downright fun. It is so easy to restructure my logic and so much less stressful trying to plan out class architecture. I spend singificantly fewer hours debugging thanks to you guys. I am not afraid of coding, in fact, I really enjoy it, which is why I was so unsatisfied with other visual scripting and AI systems. I can do nearly anything with Bolt's native interface, and when I feel it would be easier or it fancies me, I write a class or new method and route it into my graphs without having to move mountains. You peoples rock.

Anyway, here are captures of the graphs. 

Move towards without position input
Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
And inside of the MoveTowards graph.

An input always needs something plugged in. If it's supposed to be null, then a Null unit must be attached. That's most likely because the input isn't actually the value, it's a ValueInput which contains the actual value inside that type. If the port itself ends up null, it means there is no port to actually check the real value from. So it spits out that error message.

just add a null unit attached to do the same and all is good.

I agree on everything else, such a smooth plugin, that definitely makes programming more enjoyable. Keep it up!


I see what you're trying to accomplish here, but it's a bit tricky. Even Jason's workaround won't work, because a vector is a struct type and is therefore not nullable. 

One solution I can see is wrapping your MoveTowards macro inside a MoveTowardsSimple macro that doesn't have the input ports, and specifies the values for Position and Target. 

Thanks for the kind words about the plugin, glad you like it :)