View in #engine_unreal on Slack
@TooL: Just tossed up the base class I’ve been using for tickable PySide2 Windows on the github wiki
https://github.com/techartorg/TAO-Wiki/wiki/Tickable-PySide2-Window-BaseClass
Hopefully people find it useful
@TooL: Thanks to help from @robberyman I finally got menus being made and py executing in UE4 py
def main():
print("Creating Menus!")
menus = unreal.ToolMenus.get()
# Find the 'Main' menu, this should not fail,
# but if we're looking for a menu we're unsure about 'if not'
# works as nullptr check,
main_menu = menus.find_menu("LevelEditor.MainMenu")
if not main_menu:
print("Failed to find the 'Main' menu. Something is wrong in the force!")
entry = unreal.ToolMenuEntry(
name="Python.Tools",
# If you pass a type that is not supported Unreal will let you know,
type=unreal.MultiBlockType.MENU_ENTRY,
# Insert as first item in menu
insert_position=unreal.ToolMenuInsert("", unreal.ToolMenuInsertType.FIRST)
)
entry.set_label("YourMenuItemName")
# this is what gets executed on click
entry.set_string_command(unreal.ToolMenuStringCommandType.PYTHON, string=("from foo import bar;bar.main()"))
# add a new menu called PyTools to the MainMenu bar
script_menu = main_menu.add_sub_menu(main_menu.get_name(), "PythonTools", "Tools", "PyTools")
# add our new entry to the new menu
script_menu.add_menu_entry("Scripts",entry)
# refresh the UI
menus.refresh_all_widgets()
if __name__ == '__main__':
main()
In case anyone else is so inclined to not want to do it through C++
@il_berna: Super cool @TooL!!
Immediately stolen:rolling_on_the_floor_laughing:
@TooL: that’s all good and fine, tbf a lot of this is from @robberyman I spent way too much time not realizing that the mainMenu would need to have add_sub_menu to get a new menu added…but I did get the string_command all on ma owwwn
@bob.w: Does it only take string commands? or can you pass it a callable object?
@gamato: I also would like to know ^
@TooL: I’ve not been about to get anything other than string command myself but I’m a newb at this ue4 stuff still have
Couldn’t find a combo to feed it a script or anything like that
@bob.w: Yeah, poking through the docs (HAHAHAHAH) it doesn’t look there is any other way to add a command