If you do not want to worry about creating a race condition and having to close UE4Editor before shutting down, as mentioned in the other answer, then there is a nice app called EventScripts, for $3.99 USD at the App Store, that you can use to trigger AppleScript scripts and or Shell scripts when certain events are triggered.
Here's an example AppleScript script that will hide/show the Dock when UE4Editor launches/quits:
on run eventArgs
set theAppName to applicationName in eventArgs
set theTrigger to trigger in eventArgs
if theTrigger is "Application launched" and theAppName is "UE4Editor" then
else if theTrigger is "Application quit" and theAppName is "UE4Editor" then
tell application "System Events"
set autohide of dock preferences to b
In Script Editor, save the above AppleScript code as, e.g., UE4Editor - On Open and Close.scpt in ~/Library/Application Scripts/net.mousedown.EventScripts/, (after EventScripts is installed).
Now in EventScripts, add the same script twice, while setting the Event for one to Application launched and the other to Application quit.
Now, when UE4Editor launches, the Dock is hidden, and when UE4Editor quits the Dock is unhidden.
EventScripts has a long list of events it can trigger a script on. Check out the links below for more information:
Note: I'm not affiliated with the developer of EventScripts, just a satisfied customer.