Skip to content

Prepend monobehaviour base fields to generated typetrees #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2025
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
8 changes: 7 additions & 1 deletion UnityPy/files/ObjectReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ def _try_monobehaviour_node(self, base_node: TypeTreeNode) -> TypeTreeNode:
raise ValueError("No typetree generator set!")
monobehaviour = cast(MonoBehaviour, self.parse_as_object(base_node, check_read=False))
script = monobehaviour.m_Script.deref_parse_as_object()
node = generator.get_nodes_up(script.m_AssemblyName, f"{script.m_Namespace}.{script.m_ClassName}")

if script.m_Namespace != "":
fullname = f"{script.m_Namespace}.{script.m_ClassName}"
else:
fullname = script.m_ClassName

node = generator.get_nodes_up(base_node, script.m_AssemblyName, fullname)
if node:
return node
else:
Expand Down
3 changes: 2 additions & 1 deletion UnityPy/helpers/TypeTreeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def load_local_dll_folder(self, dll_dir: str):
data = f.read()
self.load_dll(data)

def get_nodes_up(self, assembly: str, fullname: str) -> TypeTreeNode:
def get_nodes_up(self, base_node: TypeTreeNode, assembly: str, fullname: str) -> TypeTreeNode:
root = self.cache.get((assembly, fullname))
if root is not None:
return root
Expand All @@ -60,6 +60,7 @@ def get_nodes_up(self, assembly: str, fullname: str) -> TypeTreeNode:
0,
0,
m_MetaFlag=base_root.m_MetaFlag,
m_Children=base_node.m_Children[:],
Copy link
Owner

Choose a reason for hiding this comment

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

Hard to say if a copy is really necessary.

)
stack: List[TypeTreeNode] = []
parent = root
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dynamic = ["version"]

[project.optional-dependencies]
# optional dependencies must be lowercase/normalized
ttgen = ["typetreegeneratorapi>=0.0.5"]
ttgen = ["typetreegeneratorapi>=0.0.7"]
full = ["unitypy[ttgen]"]
tests = ["pytest", "pillow", "psutil", "unitypy[full]"]
dev = ["ruff", "unitypy[tests]"]
Expand Down