Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
1
Question by Raggnarock · Aug 09, 2012 at 12:00 PM · meshinvisibleinstantiatedskinned

Cant see mesh of instantiated skinned mesh renderer

Hey,

So I've been working on a character customiser for my game, and when I instantiate a prefab with a skinned mesh renderer (as a child to a socket of a character template) I cannot see the mesh. It has a standard diffuse shader applied to it, and I can select the game object and see its bounds, but I cant see the mesh. What could be the cause of this?

Comment
Add comment · Show 2
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
avatar image dchen05 · Feb 25, 2013 at 06:38 PM 0
Share

Did you ever figure out the cause of this?

avatar image Barbadel · Nov 03, 2015 at 01:58 PM 0
Share

I'd love to know too.

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by vonlindberg · Mar 07, 2017 at 04:21 PM

This happens because the SkinnedMeshRenderer needs references to the bones, and these references are broken when you instantiate it from a prefab.

You need to set the "rootBone" and "bones" properties of the SkinnedMeshRenderer component after instantiating it. The latter is an array of transforms which can be built from the root bone using the following functions:

     Transform[] BuildBonesArray (Transform rootBone)
     {
         List<Transform> boneList = new List<Transform> ();
         ExtractBonesRecursively (rootBone, ref boneList);
         return boneList.ToArray ();
     }
 
     void ExtractBonesRecursively (Transform bone, ref List<Transform> boneList)
     {
         boneList.Add (bone);
 
         for (int i = 0; i < bone.childCount; i++)
         {
             ExtractBonesRecursively (bone.GetChild (i), ref boneList);
         }
     }
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
avatar image
1

Answer by Ragee · Jun 29, 2020 at 08:52 AM

Those functions indeed makes the mesh visible but I get a new issue as seen in picture below:

https://ibb.co/6PsNfhz

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
avatar image
0

Answer by ShawnRG · Dec 03, 2020 at 11:31 AM

I had the same issue, this was because the order of the bones added to the array is important. The first thing I did is to take a prefab where the SkinnedMeshRenderer rendered correctly, added a small script to it to print out the SkinnedMeshRenderer.bones array. I then saw that the order was completely different. I then just reordered the bone hierarchy to match the one in the working prefab.

Note: Also make sure to skip disabled bones by wrapping the ExtractBonesRecursively call in an if statement

          var child = bone.GetChild(i);
          if (child.gameObject.activeInHierarchy)
          {
             ExtractBonesRecursively (child, ref boneList);
          }

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
avatar image
0

Answer by MagyarPeter · Sep 25, 2021 at 02:47 PM

 public class CopyBones : MonoBehaviour
 {
     private void Awake()
     {
         SkinnedMeshRenderer smr = GetComponent<SkinnedMeshRenderer>();
         print(transform.parent);
         SkinnedMeshRenderer example = transform.parent.GetComponent<Example>().example;
         smr.rootBone = e.rootBone;
         smr.bones = e.bones;
     }
 }
 
 public class Example : MonoBehaviour
 {
 public SkinnedMeshRenderer example;
 }

//Put the "Example" script on the root of the character(not the armature, the parent of the body mesh for example).

The "Example" script's "example" will be a skinned mesh renderer that is always on the character, and works perfectly(so it wasn't instantiated from script), assign it manually.

Put the "CopyBones" script to the SkinnedMeshRenderer that you instantiated with script.

The "CopyBones"'s gameobject's parent has to contain the "Example" script.

Comment
Add comment · Show 1 · 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
avatar image MagyarPeter · Sep 25, 2021 at 02:49 PM 0
Share

I used this script to add clothes to my character via code, it worked

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.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

Skinned Cloth Disappeared... 1 Answer

is it possible to affect bones on skineed mesh by wind? 2 Answers

Mesh goes invisible after modifying vertices 2 Answers

Objects Not Visible In Low End Computer. (Shader Error) 1 Answer

Dynamically instantiated skinned mesh not playing animations 4 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