-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Extend animator controller editing capabilities #1206
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
Open
Thaina
wants to merge
7
commits into
CoplayDev:beta
Choose a base branch
from
Thaina:animation-node-graph-position-MCP
base: beta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+749
−13
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95b9c2f
get/set animation node state
Thaina e4fbd3a
add pagination and undo
Thaina 85a06b2
use instanceID as main key
Thaina 3787ea3
convert to general get/set_state_properties
Thaina 6d31609
change ID to stringID to ensure lossless in every round trip
Thaina 60d5308
Add controller_get_blend_tree / controller_edit_blend_tree actions
Thaina ba09a7f
add more edit parameter
Thaina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🔴 Critical
🧩 Analysis chain
🌐 Web query:
Unity BlendTree.CreateBlendTreeChild AddObjectToAsset persist sub-asset AnimatorController💡 Result:
To persist a BlendTree and its children as sub-assets of an AnimatorController, you must explicitly use AssetDatabase.AddObjectToAsset [1][2]. When you create a BlendTree or a child BlendTree via script, it exists only in memory [1]. To ensure it is saved alongside the AnimatorController asset, follow these guidelines: 1. Use AnimatorController.CreateBlendTreeInController to initialize the primary BlendTree [3][4]. This method automatically adds the new BlendTree as a sub-asset to the AnimatorController [3]. 2. When manually creating child BlendTrees (e.g., using BlendTree.CreateBlendTreeChild), these are generally added as sub-assets by the internal implementation [5][6]. However, if you are manually creating and adding Motion objects or nested BlendTrees, you must call AssetDatabase.AddObjectToAsset(childObject, animatorController) to ensure they are serialized into the controller file [1][7][2]. 3. Always call AssetDatabase.SaveAssets after modifying the asset structure [1][8]. Failure to do so may result in the loss of in-memory changes [1]. Example pattern: using UnityEditor; using UnityEditor.Animations; using UnityEngine; // 1. Create or load your controller AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/MyController.controller"); // 2. Create the main BlendTree within the controller controller.CreateBlendTreeInController("MyBlendTree", out BlendTree rootTree); // 3. Add a child BlendTree BlendTree childTree = rootTree.CreateBlendTreeChild(0.5f); // 4. If creating other sub-assets manually, add them to the controller // AssetDatabase.AddObjectToAsset(myNewObject, controller); // 5. Persist changes AssetDatabase.SaveAssets; Note that BlendTrees added as sub-assets are typically hidden from the Project window by default (using HideFlags) [6][2]. This is standard behavior for Unity animation sub-assets [2]. [5][3]
Citations:
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 230
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 266
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 7081
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 1090
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 6262
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 7668
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 3495
🏁 Script executed:
rg "CreateBlendTreeChild" MCPForUnity/ -A 5 -B 2Repository: CoplayDev/unity-mcp
Length of output: 1812
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 2437
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 767
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 5580
🏁 Script executed:
Repository: CoplayDev/unity-mcp
Length of output: 10613
Add explicit
AssetDatabase.AddObjectToAsset(child, controller)to persist the nested blend tree.The nested
BlendTreecreated viaCreateBlendTreeChildlacks explicit sub-asset registration. UnlikeCreateBlendTree1D/2D(which callAssetDatabase.AddObjectToAsset(blendTree, controller)at line 53 and 124), this code calls onlySetDirty(child)without registering the child into the controller asset. Thecontrollerreference is also unavailable inEditBlendTreescope sinceResolveBlendTreeonly returns theblendTree, not the controller.Retrieve the controller (e.g., via
AssetDatabase.LoadAssetAtPathusingcontrollerPathfrom@params) and callAssetDatabase.AddObjectToAsset(child, controller)before or afterSetDirty(child)to ensure the nested tree persists on reload.🤖 Prompt for AI Agents