• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RoosStudio · Oct 15, 2022 at 04:44 PM · bonesskinnedmeshrendererocclusion cullingarmatureroot bone

Skinned Mesh Renderer -> Root Bone

Blender SIde: I have a character wich has many body parts, so i decided to clone right side arm and leg to the left side. Deleted all the vertices and parented / painted the weight on the mesh.

Unity side: After importing the .fbx, i noticed that the generated SMR has the right side root on every part of the left members.

The problem with it, is that the bound will follow the wrong bone and therefore the wrong mesh, so parts of the body will desapear from camera at wrong moment (because the bound is out of the camera, but the mesh is not). I could just manually adjust the bounds, but it feels like there should be a better solution to t$$anonymous$$s.

e.g.: the missing arms in the following image. alt text

screenshot-from-2022-10-15-13-41-09.png (166.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by RoosStudio · Oct 15, 2022 at 09:27 PM

I have searched the entire internet for an answer and found none, so i decide to create a way of not doing t$$anonymous$$s manually.

First, i created a class to generate a button for my function on the inspector:

 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(BoundRecalculate))]
 public class BoundRecalculatorMenu : Editor
 {
     public override void OnInspectorGUI()
     {
         DrawDefaultInspector();
 
         BoundRecalculate script = (BoundRecalculate)target;
 
         if(GUILayout.Button("Recalculate Bounds")) {
             script.calculate();
         }
     }
 }
 



then, i created a function to recalculate the bounds of my meshes:

 using UnityEngine;
 
 public class BoundRecalculate : MonoBehaviour
 {
     [SerializeField]
     GameObject target;
 
     public void calculate() {
         foreach( Transform c$$anonymous$$ld in target.transform ) {
             if(c$$anonymous$$ld.GetComponent<SkinnedMeshRenderer>() != null) {
                 SkinnedMeshRenderer skinnedMeshRenderer = c$$anonymous$$ld.GetComponent<SkinnedMeshRenderer>();
                     skinnedMeshRenderer.rootBone = skinnedMeshRenderer.bones[skinnedMeshRenderer.sharedMesh.boneWeights[0].boneIndex0];
                     skinnedMeshRenderer.updateWhenOffscreen = true;
                     Bounds bounds = new Bounds();
                     Vector3 center = skinnedMeshRenderer.localBounds.center;
                     Vector3 extents = skinnedMeshRenderer.localBounds.extents;
                     bounds.center = center;
                     bounds.extents = extents;
                     skinnedMeshRenderer.updateWhenOffscreen = false;
                     skinnedMeshRenderer.localBounds = bounds;
             }
         }
     }
 }



what t$$anonymous$$s does it to get the target object and find every single c$$anonymous$$ld that has a Skinned Mesh Renderer on it, then it get the bone the first bone of the first vertice ( not the most used bone, but the first, t$$anonymous$$s may be a problem to some cases, but worked fine for my case ), and set it as root bone (t$$anonymous$$s is needed so the bound will follow the character movement), last but not least, it sets the updatewhenoffscreen to on, so we can get the correct bound to that mesh, and then turn it off, setting the saved values to our finished bound.

I hope t$$anonymous$$s come to be usefull to others, sorry for my bad english.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

144 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get so-called "root bone" using Unityscript/c# 2 Answers

Can I import clothing attached to a character that has already been imported into Unity? 2 Answers

How to deal with an extra spine bone? 1 Answer

Export FBX files to unity that contain bones without weights 1 Answer

Bones work when manually adding object to scene, but not when instantiated in code; why? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges