Skip to content

Commit 7b7b1e3

Browse files
authored
Merge pull request #6 from GPLgithub/master
6645 ue5 fixes (#10)
2 parents 64c4bb3 + 9cd4d3a commit 7b7b1e3

File tree

6 files changed

+268
-63
lines changed

6 files changed

+268
-63
lines changed

engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def pre_app_init(self):
8888

8989
self.init_qt_app()
9090

91-
# Load the tk_unreal module (the Shotgun engine wrapper for Unreal)
91+
# Load the tk_unreal module (the SG engine wrapper for Unreal)
9292
self.tk_unreal = self.import_module("tk_unreal")
9393
self.unreal_sg_engine = self.tk_unreal.config.wrapper_instance
9494

hooks/tk-multi-publish2/basic/collector.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def collect_selected_assets(self, parent_item):
136136
:param parent_item: Parent Item instance
137137
"""
138138
unreal_sg = sgtk.platform.current_engine().unreal_sg_engine
139-
140139
# Iterate through the selected assets and get their info and add them as items to be published
141140
for asset in unreal_sg.selected_assets:
142141
asset_name = str(asset.asset_name)

hooks/tk-multi-publish2/basic/publish_movie.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ def _unreal_render_sequence_with_sequencer(self, output_path, unreal_map_path, s
756756
# Prevent SG TK to try to bootstrap in the new process
757757
if "UE_SHOTGUN_BOOTSTRAP" in run_env:
758758
del run_env["UE_SHOTGUN_BOOTSTRAP"]
759+
if "UE_SHOTGRID_BOOTSTRAP" in run_env:
760+
del run_env["UE_SHOTGRID_BOOTSTRAP"]
759761

760762
subprocess.call(cmdline_args, env=run_env)
761763

@@ -896,6 +898,8 @@ def _unreal_render_sequence_with_movie_queue(self, output_path, unreal_map_path,
896898
# Prevent SG TK to try to bootstrap in the new process
897899
if "UE_SHOTGUN_BOOTSTRAP" in run_env:
898900
del run_env["UE_SHOTGUN_BOOTSTRAP"]
901+
if "UE_SHOTGRID_BOOTSTRAP" in run_env:
902+
del run_env["UE_SHOTGRID_BOOTSTRAP"]
899903
self.logger.info("Running %s" % cmd_args)
900904
subprocess.call(cmd_args, env=run_env)
901905
return os.path.isfile(output_path), output_path

plugins/basic/python/tk_unreal_basic/plugin_bootstrap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ def _on_engine_initialized():
6868
sgtk_logger.debug("tk-unreal finished initialization.")
6969

7070
import unreal
71-
72-
unreal.ShotgunEngine.get_instance().on_engine_initialized()
71+
# ShotgunEngine was renamed to ShotgridEngine from UE5
72+
if hasattr(unreal, "ShotgridEngine"):
73+
unreal.ShotgridEngine.get_instance().on_engine_initialized()
74+
else:
75+
unreal.ShotgunEngine.get_instance().on_engine_initialized()
7376

7477

7578
def _initialize_manager(plugin_root_path):
@@ -87,7 +90,7 @@ def _initialize_manager(plugin_root_path):
8790

8891
# open the yaml file and read the data
8992
with open(plugin_info_yml, "r") as plugin_info_fh:
90-
plugin_info = yaml.load(plugin_info_fh)
93+
plugin_info = yaml.load(plugin_info_fh, yaml.SafeLoader)
9194

9295
base_config = plugin_info["base_configuration"]
9396
plugin_id = plugin_info["plugin_id"]

python/tk_unreal/unreal_sg_engine.py

Lines changed: 96 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,91 @@
88
import sys
99
import os
1010

11-
unreal.log("Loading Shotgun Engine for Unreal from {}".format(__file__))
11+
unreal.log("Loading SG Engine for Unreal from {}".format(__file__))
12+
13+
# Shotgun integration components were renamed to Shotgrid from UE5
14+
if hasattr(unreal, "ShotgridEngine"):
15+
UESGEngine = unreal.ShotgridEngine
16+
17+
else:
18+
UESGEngine = unreal.ShotgunEngine
1219

1320

1421
@unreal.uclass()
15-
class ShotgunEngineWrapper(unreal.ShotgunEngine):
22+
class ShotgunEngineWrapper(UESGEngine):
1623

1724
def _post_init(self):
1825
"""
1926
Equivalent to __init__ but will also be called from C++
2027
"""
2128
config.wrapper_instance = self
2229

23-
@unreal.ufunction(override=True)
24-
def get_shotgun_menu_items(self):
25-
"""
26-
Returns the list of available menu items to populate the Shotgun menu in Unreal
27-
"""
28-
menu_items = []
29-
30-
engine = sgtk.platform.current_engine()
31-
menu_items = self.create_menu(engine)
32-
33-
unreal.log("get_shotgun_menu_items returned: {0}".format(menu_items.__str__()))
34-
35-
return menu_items
30+
# Shotgun integration components were renamed to Shotgrid from UE5
31+
# these new methods are not available in UE4, we provide backward
32+
# compatibility so scripts using the old methods don't break in UE5,
33+
# but also forward compatibility, so users can start using the new
34+
# names in UE4.
35+
if hasattr(UESGEngine, "get_shotgrid_menu_items"):
36+
@unreal.ufunction(override=True)
37+
def get_shotgrid_menu_items(self):
38+
"""
39+
Returns the list of available menu items to populate the SG menu in Unreal.
40+
"""
41+
menu_items = []
42+
43+
engine = sgtk.platform.current_engine()
44+
menu_items = self.create_menu(engine)
45+
46+
unreal.log("get_shotgrid_menu_items returned: {0}".format(menu_items.__str__()))
47+
48+
return menu_items
49+
50+
def get_shotgun_menu_items(self):
51+
"""
52+
Provide backward compatibility.
53+
"""
54+
unreal.log_warning("get_shotgun_menu_items is deprecated, get_shotgrid_menu_items should be used instead.")
55+
return self.get_shotgrid_menu_items()
56+
else:
57+
@unreal.ufunction(override=True)
58+
def get_shotgun_menu_items(self):
59+
"""
60+
Returns the list of available menu items to populate the SG menu in Unreal.
61+
"""
62+
menu_items = []
63+
64+
engine = sgtk.platform.current_engine()
65+
menu_items = self.create_menu(engine)
66+
67+
unreal.log_warning("get_shotgun_menu_items is deprecated, get_shotgrid_menu_items should be used instead.")
68+
unreal.log("get_shotgun_menu_items returned: {0}".format(menu_items.__str__()))
69+
70+
return menu_items
71+
72+
def get_shotgrid_menu_items(self):
73+
"""
74+
Provide forward compatibility.
75+
"""
76+
return self.get_shotgun_menu_items()
77+
78+
if hasattr(UESGEngine, "get_shotgrid_work_dir"):
79+
def get_shotgun_work_dir(self, *args, **kwargs):
80+
"""
81+
Provide backward compatibility.
82+
"""
83+
unreal.log_warning("get_shotgun_work_dir is deprecated, get_shotgrid_work_dir should be used instead.")
84+
return self.get_shotgrid_work_dir(*args, **kwargs)
85+
else:
86+
def get_shotgrid_work_dir(self, *args, **kwargs):
87+
"""
88+
Provide forward compatibility.
89+
"""
90+
return self.get_shotgun_work_dir(*args, **kwargs)
3691

3792
@unreal.ufunction(override=True)
3893
def execute_command(self, command_name):
3994
"""
40-
Callback to execute the menu item selected in the Shotgun menu in Unreal
95+
Callback to execute the menu item selected in the SG menu in Unreal.
4196
"""
4297
engine = sgtk.platform.current_engine()
4398

@@ -58,9 +113,9 @@ def _get_command_override(self, engine, command_name, default_callback):
58113
:param command_name: The command name to override
59114
:param default_callback: The callback to use when there's no override
60115
"""
61-
# Override the Shotgun Panel command to use the Shotgun Entity context
116+
# Override the SG Panel command to use the SG Entity context
62117
# and also reuse the dialog if one already exists
63-
if command_name == "Shotgun Panel...":
118+
if command_name in ["Shotgun Panel...", "ShotGrid Panel..."]:
64119
def show_shotgunpanel_with_context():
65120
app = engine.apps["tk-multi-shotgunpanel"]
66121
entity_type, entity_id = self._get_context(engine)
@@ -75,7 +130,7 @@ def show_shotgunpanel_with_context():
75130

76131
def _get_context_url(self, engine):
77132
"""
78-
Get the Shotgun entity URL from the metadata of the selected asset, if present
133+
Get the SG entity URL from the metadata of the selected asset, if present.
79134
"""
80135
# By default, use the URL of the project
81136
url = engine.context.shotgun_url
@@ -110,12 +165,12 @@ def _get_context_url(self, engine):
110165

111166
def _get_context(self, engine):
112167
"""
113-
Get the Shotgun context (entity type and id) that is associated with the selected menu command
168+
Get the SG context (entity type and id) that is associated with the selected menu command.
114169
"""
115170
entity_type = None
116171
entity_id = None
117172

118-
# The context is derived from the Shotgun entity URL
173+
# The context is derived from the SG entity URL
119174
url = self._get_context_url(engine)
120175
if url:
121176
# Extract entity type and id from URL, which should follow this pattern:
@@ -173,7 +228,7 @@ def shutdown(self):
173228

174229
engine = sgtk.platform.current_engine()
175230
if engine is not None:
176-
unreal.log("Shutting down ShotgunEngineWrapper")
231+
unreal.log("Shutting down %s" % self.__class__.__name__)
177232

178233
# destroy_engine of tk-unreal will take care of closing all dialogs that are still opened
179234
engine.destroy()
@@ -184,12 +239,12 @@ def shutdown(self):
184239
Menu generation functionality for Unreal (based on the 3ds max Menu Generation implementation)
185240
186241
Actual menu creation is done in Unreal
187-
The following functions simply generate a list of available commands that will populate the Shotgun menu in Unreal
242+
The following functions simply generate a list of available commands that will populate the SG menu in Unreal
188243
"""
189244

190245
def create_menu(self, engine):
191246
"""
192-
Populate the Shotgun Menu with the available commands
247+
Populate the SG Menu with the available commands.
193248
"""
194249
menu_items = []
195250

@@ -257,9 +312,13 @@ def _add_menu_item_from_command(self, menu_items, command):
257312

258313
def _add_menu_item(self, menu_items, type, name="", title="", description=""):
259314
"""
260-
Adds a new Unreal ShotgunMenuItem to the menu items
315+
Adds a new Unreal SG MenuItem to the menu items.
261316
"""
262-
menu_item = unreal.ShotgunMenuItem()
317+
# Shotgun integration components were renamed to Shotgrid from UE5
318+
if hasattr(unreal, "ShotgridMenuItem"):
319+
menu_item = unreal.ShotgridMenuItem()
320+
else:
321+
menu_item = unreal.ShotgunMenuItem()
263322
menu_item.title = title
264323
menu_item.name = name
265324
menu_item.type = type
@@ -275,15 +334,23 @@ def _start_contextual_menu(self, engine, menu_items):
275334

276335
self._add_menu_item(menu_items, "context_begin", ctx_name, ctx_name)
277336

278-
engine.register_command("Jump to Shotgun", self._jump_to_sg, {"type": "context_menu", "short_name": "jump_to_sg"})
337+
engine.register_command(
338+
"Jump to ShotGrid",
339+
self._jump_to_sg,
340+
{"type": "context_menu", "short_name": "jump_to_sg"}
341+
)
279342

280343
# Add the menu item only when there are some file system locations.
281344
if ctx.filesystem_locations:
282-
engine.register_command("Jump to File System", self._jump_to_fs, {"type": "context_menu", "short_name": "jump_to_fs"})
345+
engine.register_command(
346+
"Jump to File System",
347+
self._jump_to_fs,
348+
{"type": "context_menu", "short_name": "jump_to_fs"}
349+
)
283350

284351
def _jump_to_sg(self):
285352
"""
286-
Callback to Jump to Shotgun from context
353+
Callback to Jump to SG from context.
287354
"""
288355
from sgtk.platform.qt5 import QtGui, QtCore
289356
url = self._get_context_url(sgtk.platform.current_engine())

0 commit comments

Comments
 (0)