Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def pre_app_init(self):

self.init_qt_app()

# Load the tk_unreal module (the Shotgun engine wrapper for Unreal)
# Load the tk_unreal module (the SG engine wrapper for Unreal)
self.tk_unreal = self.import_module("tk_unreal")
self.unreal_sg_engine = self.tk_unreal.config.wrapper_instance

Expand Down
1 change: 0 additions & 1 deletion hooks/tk-multi-publish2/basic/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def collect_selected_assets(self, parent_item):
:param parent_item: Parent Item instance
"""
unreal_sg = sgtk.platform.current_engine().unreal_sg_engine

# Iterate through the selected assets and get their info and add them as items to be published
for asset in unreal_sg.selected_assets:
asset_name = str(asset.asset_name)
Expand Down
4 changes: 4 additions & 0 deletions hooks/tk-multi-publish2/basic/publish_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@ def _unreal_render_sequence_with_sequencer(self, output_path, unreal_map_path, s
# Prevent SG TK to try to bootstrap in the new process
if "UE_SHOTGUN_BOOTSTRAP" in run_env:
del run_env["UE_SHOTGUN_BOOTSTRAP"]
if "UE_SHOTGRID_BOOTSTRAP" in run_env:
del run_env["UE_SHOTGRID_BOOTSTRAP"]

subprocess.call(cmdline_args, env=run_env)

Expand Down Expand Up @@ -896,6 +898,8 @@ def _unreal_render_sequence_with_movie_queue(self, output_path, unreal_map_path,
# Prevent SG TK to try to bootstrap in the new process
if "UE_SHOTGUN_BOOTSTRAP" in run_env:
del run_env["UE_SHOTGUN_BOOTSTRAP"]
if "UE_SHOTGRID_BOOTSTRAP" in run_env:
del run_env["UE_SHOTGRID_BOOTSTRAP"]
self.logger.info("Running %s" % cmd_args)
subprocess.call(cmd_args, env=run_env)
return os.path.isfile(output_path), output_path
9 changes: 6 additions & 3 deletions plugins/basic/python/tk_unreal_basic/plugin_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ def _on_engine_initialized():
sgtk_logger.debug("tk-unreal finished initialization.")

import unreal

unreal.ShotgunEngine.get_instance().on_engine_initialized()
# ShotgunEngine was renamed to ShotgridEngine from UE5
if hasattr(unreal, "ShotgridEngine"):
unreal.ShotgridEngine.get_instance().on_engine_initialized()
else:
unreal.ShotgunEngine.get_instance().on_engine_initialized()


def _initialize_manager(plugin_root_path):
Expand All @@ -87,7 +90,7 @@ def _initialize_manager(plugin_root_path):

# open the yaml file and read the data
with open(plugin_info_yml, "r") as plugin_info_fh:
plugin_info = yaml.load(plugin_info_fh)
plugin_info = yaml.load(plugin_info_fh, yaml.SafeLoader)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to get rid of a yaml warning, that was not in the first PR you reviewed.


base_config = plugin_info["base_configuration"]
plugin_id = plugin_info["plugin_id"]
Expand Down
125 changes: 96 additions & 29 deletions python/tk_unreal/unreal_sg_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,91 @@
import sys
import os

unreal.log("Loading Shotgun Engine for Unreal from {}".format(__file__))
unreal.log("Loading SG Engine for Unreal from {}".format(__file__))

# Shotgun integration components were renamed to Shotgrid from UE5
if hasattr(unreal, "ShotgridEngine"):
UESGEngine = unreal.ShotgridEngine

else:
UESGEngine = unreal.ShotgunEngine


@unreal.uclass()
class ShotgunEngineWrapper(unreal.ShotgunEngine):
class ShotgunEngineWrapper(UESGEngine):

def _post_init(self):
"""
Equivalent to __init__ but will also be called from C++
"""
config.wrapper_instance = self

@unreal.ufunction(override=True)
def get_shotgun_menu_items(self):
"""
Returns the list of available menu items to populate the Shotgun menu in Unreal
"""
menu_items = []

engine = sgtk.platform.current_engine()
menu_items = self.create_menu(engine)

unreal.log("get_shotgun_menu_items returned: {0}".format(menu_items.__str__()))

return menu_items
# Shotgun integration components were renamed to Shotgrid from UE5
# these new methods are not available in UE4, we provide backward
# compatibility so scripts using the old methods don't break in UE5,
# but also forward compatibility, so users can start using the new
# names in UE4.
if hasattr(UESGEngine, "get_shotgrid_menu_items"):
@unreal.ufunction(override=True)
def get_shotgrid_menu_items(self):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be sufficient to leave the old methods in here, calling the new instead? Maybe add a deprecation docstring or warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good to support backward and forward compatibility. We could log a deprecation warning in "shotgun" methods, mentioning "shotgrid" methods, is it what you have in mind?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my suggestion was poorly written. What I meant to say was, would it be sufficient to leave all methods at the top level (no conditional) and have the old shotgun methods call the new shotgrid methods while also logging a warning when the old ones are called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not: the new methods are only available from UE5, we can’t call them in UE4. So the tests and mix and matches are needed.

"""
Returns the list of available menu items to populate the SG menu in Unreal.
"""
menu_items = []

engine = sgtk.platform.current_engine()
menu_items = self.create_menu(engine)

unreal.log("get_shotgrid_menu_items returned: {0}".format(menu_items.__str__()))

return menu_items

def get_shotgun_menu_items(self):
"""
Provide backward compatibility.
"""
unreal.log_warning("get_shotgun_menu_items is deprecated, get_shotgrid_menu_items should be used instead.")
return self.get_shotgrid_menu_items()
else:
@unreal.ufunction(override=True)
def get_shotgun_menu_items(self):
"""
Returns the list of available menu items to populate the SG menu in Unreal.
"""
menu_items = []

engine = sgtk.platform.current_engine()
menu_items = self.create_menu(engine)

unreal.log_warning("get_shotgun_menu_items is deprecated, get_shotgrid_menu_items should be used instead.")
unreal.log("get_shotgun_menu_items returned: {0}".format(menu_items.__str__()))

return menu_items

def get_shotgrid_menu_items(self):
"""
Provide forward compatibility.
"""
return self.get_shotgun_menu_items()

if hasattr(UESGEngine, "get_shotgrid_work_dir"):
def get_shotgun_work_dir(self, *args, **kwargs):
"""
Provide backward compatibility.
"""
unreal.log_warning("get_shotgun_work_dir is deprecated, get_shotgrid_work_dir should be used instead.")
return self.get_shotgrid_work_dir(*args, **kwargs)
else:
def get_shotgrid_work_dir(self, *args, **kwargs):
"""
Provide forward compatibility.
"""
return self.get_shotgun_work_dir(*args, **kwargs)

@unreal.ufunction(override=True)
def execute_command(self, command_name):
"""
Callback to execute the menu item selected in the Shotgun menu in Unreal
Callback to execute the menu item selected in the SG menu in Unreal.
"""
engine = sgtk.platform.current_engine()

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

def _get_context_url(self, engine):
"""
Get the Shotgun entity URL from the metadata of the selected asset, if present
Get the SG entity URL from the metadata of the selected asset, if present.
"""
# By default, use the URL of the project
url = engine.context.shotgun_url
Expand Down Expand Up @@ -110,12 +165,12 @@ def _get_context_url(self, engine):

def _get_context(self, engine):
"""
Get the Shotgun context (entity type and id) that is associated with the selected menu command
Get the SG context (entity type and id) that is associated with the selected menu command.
"""
entity_type = None
entity_id = None

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

engine = sgtk.platform.current_engine()
if engine is not None:
unreal.log("Shutting down ShotgunEngineWrapper")
unreal.log("Shutting down %s" % self.__class__.__name__)

# destroy_engine of tk-unreal will take care of closing all dialogs that are still opened
engine.destroy()
Expand All @@ -184,12 +239,12 @@ def shutdown(self):
Menu generation functionality for Unreal (based on the 3ds max Menu Generation implementation)

Actual menu creation is done in Unreal
The following functions simply generate a list of available commands that will populate the Shotgun menu in Unreal
The following functions simply generate a list of available commands that will populate the SG menu in Unreal
"""

def create_menu(self, engine):
"""
Populate the Shotgun Menu with the available commands
Populate the SG Menu with the available commands.
"""
menu_items = []

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

def _add_menu_item(self, menu_items, type, name="", title="", description=""):
"""
Adds a new Unreal ShotgunMenuItem to the menu items
Adds a new Unreal SG MenuItem to the menu items.
"""
menu_item = unreal.ShotgunMenuItem()
# Shotgun integration components were renamed to Shotgrid from UE5
if hasattr(unreal, "ShotgridMenuItem"):
menu_item = unreal.ShotgridMenuItem()
else:
menu_item = unreal.ShotgunMenuItem()
menu_item.title = title
menu_item.name = name
menu_item.type = type
Expand All @@ -275,15 +334,23 @@ def _start_contextual_menu(self, engine, menu_items):

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

engine.register_command("Jump to Shotgun", self._jump_to_sg, {"type": "context_menu", "short_name": "jump_to_sg"})
engine.register_command(
"Jump to ShotGrid",
self._jump_to_sg,
{"type": "context_menu", "short_name": "jump_to_sg"}
)

# Add the menu item only when there are some file system locations.
if ctx.filesystem_locations:
engine.register_command("Jump to File System", self._jump_to_fs, {"type": "context_menu", "short_name": "jump_to_fs"})
engine.register_command(
"Jump to File System",
self._jump_to_fs,
{"type": "context_menu", "short_name": "jump_to_fs"}
)

def _jump_to_sg(self):
"""
Callback to Jump to Shotgun from context
Callback to Jump to SG from context.
"""
from sgtk.platform.qt5 import QtGui, QtCore
url = self._get_context_url(sgtk.platform.current_engine())
Expand Down
Loading