How to change variables from blueprints with an Editor Utility Widget checkbox?

Hi, I’m making a simple Editor Utility Widget mainly to set debug variables quickly in my game.

one of them is a bool in my characterBP named “bLoadInitialDialogue”, and the other bool is in my game instance, named “bLoadLastSAve”. there’s also a string variable in my game instance with the game version i’d like to set up from this EUW.

the traditional way to do so would be casting to the player character, or the game instance, and setting those variables, but since I want to edit these values in the editor, and not during run time, casting doesn’t work, and I’m not sure how exactly to indirectly change a value from a blueprint class variable instead of a spawned actor in game.

image

ideas?

So, for a minute I thought I was getting somewhere with these nodes:

but nope, can’t find a way to connect them to change a variable default in an existing blueprint asset.

can this even be done?

Do you want to change the variable for the asset in the content folder or for assets that are in your level?
You cannot use the standard methods like simple casting as the game is not running usually while the EUW is being called.
Depending on the answer there are different methods to achieve this.

1 Like

I want to change a variable to the asset in my content folder yes, so a default value for that class

1 Like

obraz

Project file
ToolEUW.zip (32.2 KB)

If you want the change to also be automatically saved then add a node at the end
obraz

Hmm just read the content folder portion. Not sure if it’s possible without c++.

1 Like

Right yeah, the two classes I want to change default values are: my custom player character, and my game instance, which are not in the level.

if there was a way of doing so in blueprints, it would be fantastic. but if not, I would give a try with C++, as I’ve been opening these two blueprints thousands of times a day to change those values for debugging

no idea why the first print string returns the blueprint, but the second returns empty.

Also, just spent the last hour trying to get chatgpt to produce a python script for that, without any luck, so I guess I shouldn’t bother asking it to give me a c++ code

Ok narrowed down how it can be done in python. No c++ needed

Just swap out the blueprint path / name and property and you have a tool ready

It can probably be cleaned up with an append node and one function but it works!

Python text for true

import unreal

bp_object = unreal.EditorAssetLibrary.load_blueprint_class('/Game/BP_Test')
bp_default_oject = unreal.get_default_object(bp_object)
bp_default_oject.set_editor_property("ShowInitialDialog",True)
unreal.EditorAssetLibrary.save_asset('/Game/BP_Test', only_if_is_dirty=False)

@fael097 I converted the python script to function to simplify it


ToolEUW_2.zip (62.5 KB)

1 Like

That is just awesome! thank you so much.

I burned my head for a bit trying to make the checkbox stay checked when compiling the EUW, just to realize I could use your function itself for that lol:

Do you think there’s a better way than this?

You can just tick save asset on the final set property node in the chain. No need to save asset changes mid property change. It will speed up the process. Just save out at the end.

I was thinking about maybe passing in an key value array as an input, but I didn’t want it to be too complex.

Instead of enforcing the checkbox default value to true, perhaps a reverse function could be used to read the value.

1 Like

Ah, makes sense to save only in the end, but in this case it’s two different assets, so I suppose it’s needed?

the second node in the chain I’m changing a “buffer” variable in the EUW itself that holds the checked state for its own checkbox, which is called on construct to set the checkbox state every time I compile the blueprint, so it retains the current state when I’m doing changes to it

So i tried to use your function with a text variable and a string variable, but it doesn’t seem to work. Are there any quick changes to make it work with different types of variables?

edit: nevermind, just had to append quotes before and after the string, text. it works great!

Added a read function. If it was in c++ I could probably return a wildcard value. Otherwise it needs a text comparison for Boolean :confused:

Set initial variable

Get Function

ToolEUW3.zip (51.3 KB)

1 Like

Awesome, works great.

I just noticed some weird behavior.

In my player character blueprint, even though the EUW checkbox does indeed change the variable value, the game doesn’t recognize it:

so this variable in the char blueprint was set via the EUW function, it’s properly shown as True, but the branch considers it false.

if I uncheck and check again from the character blueprint itself, it works.

now, I set it exactly the same for changing a variable in my game instance blueprint, and it works through the EUW function just fine.

A workaround that works is setting up the ShowInitialDialog var in my game instance instead of player character, and getting it from there:

I suppose it’s not a problem storing all my “global” variables there since I can access game instance anywhere, but it’s just odd that the player character BP doesn’t recognize the bool value, even though it appears to be set correctly.

It depends on how your blueprint is setup. The python script changes the default object variables. If you have “Instanced editable” turned on for the variable then it can change from instance to instance.(you would need to modify the spawned in level actors in parallel to keep instances in sync)

I would either have to extend the function to allow for instance vars to be captured or you can turn off instance instance editable and the variable will be in sync :slight_smile:

No need for extra global var complexity.

obraz

Uploaded with cache just to keep information so slightly higher size

ToolEUW4.zip (2.5 MB)

1 Like

I thought it could be the case, in fact during testing with a TestBP, it behaved like you showed, so I had it turned off in my character, but it didn’t do it. Then I’ve done some testing and apparently it’s related to parentage.

my player character is a child of “IsoPlayerCharacter”, and I have that ShowInitialDialog bool set in the parent class, not the child.

If I drag a base “IsoPlayerCharacter” into the world, it works, but it doesn’t if I drag a child class.

So even if I have the Dialog function set in a parent class, I need to have your function pointing to the actual final spawned class, then it works, even with “instance editable” turned on

A bit odd since it looks like I’m actually changing the default value of the parent BP class, but if you change the parent bool in the parent class BP, it changes the value of all child BPs, but changing via your code it seems to be changing only the parent bool, not the child bools:

I didn’t even know it was possible :smile:

It’s an inherited class. It’s doing what it’s meant to

You have the
parent A => bool set to true
child B => inherits bool setting from parent.

If you change the parent variable then the child will follow, unless you manually set the child variable to the inverse of the bool, only then will it be marked the the return to default icon

Parent


Child

The tool works as intended. You can change both the parent and the child value and they will stay once the object knows it’s new value

You would have to gather the inherited classes and apply the property though the tool in a loop.
I’ll look into it.

ToolEUW5.zip (105.3 KB)

Added derived flag to change variables in derived classes.

1 Like

Yep, it’s working perfectly! Thank you @3dRaven !

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.