I’m trying to do a couple of related things with a blueprint with no luck…
- Check to see if a variable is set.
- Unset a variable, or set it to null.
Any thoughts on how this could be done?
John
I’m trying to do a couple of related things with a blueprint with no luck…
Any thoughts on how this could be done?
John
By check to see if a variable is set, you mean if it has a value during run time? You could hook it up to a print string node or you could right click on it in your blueprint and select to watch the value (you’d see its value inside your blueprint while playing in the editor).
You can set a variable to null or unset it, alt-click on the variable and drag it into the graph to produce a Set Variable node which you can specify what that value is. You can look at this section for more information: Variables
-W
Thanks Wes… I’m talking about runtime… Ill elaborate a bit.
My main player Pawn has a variable called ‘CurrentMission’ and this should point to a specific type of Actor. I have this part done.
At certain points in the game, the player can accept a mission ONLY if there is no ‘CurrentMission’ set. So this is why at runtime I need to check to see if ‘CurrentMission’ is set and ‘Branch’ my functionality.
Related to this, once the user has completed the mission, I need to ‘Unset’ the ‘CurrentMission’ variable.
Make sense?
Regards:
John
We have a “IsValid” macro that checks to see if the variable has a null reference. This sounds like what you might want!
Fun Fact:
Double click on a macro to open it up and check out what it’s doing under the hood! Eg. IsValid, DoOnce, Gate, ForLoop etc. etc.
You can make your own macro libraries like this to make your life easier on common tasks.
Thanks, exactly what I need!
What about setting a property to null?
Was just wondering this myself, every helpful thanks!
If you leave the value pin disconnected on a Set node, that will set the object to null. We don’t have a null literal node, though that wouldn’t be a bad idea to add.
Cheers,
Michael Noland
Thanks Michael.
Michael, I’m trying to set an object to null just as you described (disconnected on a set node), but this doesn’t seem to work.
As a workaround I’ve had to create a duplicate variable of the same type which is never set and use that to signify null. I’m using the macro ‘Is Valid’ to check as well.
Any thoughts on the below image?
Gentle bump, anyone know why null comparisons don’t work given “Select Asset” is supposed to be equal to null?
This is an “interesting” example, as I don’t think most people would do it this way.
just to offer my observation.
Sorry I think the naming convention I’ve used in the image has proved confusing - I’m certainly not setting the player itself to null.
In the first image the ‘other actor’ is plugged to ‘player character c’, while what is being set to null is a variable ‘test object variable’ (which is a variable belonging to the object ‘player character c’)
In the second screenshot I’m getting a variable named ‘NULLObject’ from the player character and setting that onto the 'test object variable. NULLObject is a dummy variable that is never ever set and thus holds null inside of it. This ugly workaround is precisely needed because “Select Asset” doesn’t seem to equate to null for the test object.
(in hindsight I should have left the original names from my blueprint instead of this generic example)
maybe it’s a bug, congrats!
Hah I’m just surprised this hasn’t been widely reported before. I’ll try logging a bug in the Answers hub.
This thread on the answers hub discusses the exact issue without resolution while another one is marked resolved but only the part where you use “Select Asset” to check for null works. i.e setting an object to “select asset” itself doesn’t see to make it null.
Hi VSZ,
This does seem to work correctly for me, the following snippet prints out:
[3061.28][314]LogBlueprintUserMessages: IdleCycle1
[3061.28][314]LogBlueprintUserMessages: None
Cheers,
Michael Noland
@michael, I think VSZ is referring to set variables with a reference. Regular set var work as intended with object var.
Quite bizarre, I tried the same setup that Michael used and I’m still able to reproduce it. Maybe it’s worth mentioning the object in my case is a blueprint instance so I’m not sure if there’s something related to this that’s triggering the issue.
Either way not a big deal as I have a workaround to move ahead, will be interesting to learn what’s happening though.
LogBlueprintUserMessages: BP_PolliPlant_Greater_Knapweed_C_0
LogBlueprintUserMessages: BP_PolliPlant_Greater_Knapweed_C_0
It might have something to do with the use of “self”.