Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Cyber_Defect · Apr 17, 2013 at 02:47 AM · instantiatebonesboneweights

Bones not keeping weights after Instantiate()?

Ok, so I create an object with an IDE defined mesh. I assign boneweights based on the position.x of each vertex.

Later, I instantiate the object, I then assign the boneweights to the mesh, however when I attempt to rotate the bones, they have nothing happens.

Here is the pertinent part of my project:

         DUMMYWALL = Instantiate(DUMMYWALL,World.position,Quaternion.identity)as Transform;
         Destroy(DUMMYWALL.gameObject.GetComponent<MeshRenderer>());
         DUMMYWALL.gameObject.AddComponent<SkinnedMeshRenderer>();
         //DUMMYWALL.localScale = Scale;
         Transform[] WallBones = new Transform[2];
         Matrix4x4[] WallBP = new Matrix4x4[2];
         MeshFilter WallMeshFilter = DUMMYWALL.gameObject.GetComponent<MeshFilter>();
         SkinnedMeshRenderer WallSMRenderer = DUMMYWALL.gameObject.GetComponent<SkinnedMeshRenderer>();
         Vector3[] WallVerts = WallMeshFilter.mesh.vertices;
         WallBW = new BoneWeight[WallVerts.Length];
         for (int i = 0; i < WallVerts.Length; i++) {
             WallBW[i].boneIndex0 = 0;
             WallBW[i].weight0 = Mathf.Abs(10*WallVerts[i].x);
             WallBW[i].boneIndex1 = 1;
             WallBW[i].weight1 = (1f - (10*Mathf.Abs(WallVerts[i].x)));
         }
         
         WallBones[0] = new GameObject("Bone 0").transform;
         WallBones[0].localPosition = WallVerts[189];
         WallBones[0].parent = DUMMYWALL;
         WallBP[0] = WallBones[0].worldToLocalMatrix * transform.localToWorldMatrix;
         
         WallBones[1] = new GameObject("Bone 1").transform;
         WallBones[1].localPosition = WallVerts[2];
         WallBones[1].parent = DUMMYWALL;
         WallBP[1] = WallBones[1].worldToLocalMatrix * transform.localToWorldMatrix;
         
         //Assign collections to DUMMYWALL
         WallMeshFilter.mesh.boneWeights = WallBW;
         WallMeshFilter.mesh.bindposes = WallBP;
         WallSMRenderer.sharedMesh = WallMeshFilter.mesh;
         WallSMRenderer.bones = WallBones;
 
         Transform southwall = (Transform)Instantiate(DUMMYWALL,(nCMfilter.mesh.vertices[0]*.99f),Quaternion.identity);
         southwall.name = "SouthWall";
         southwall.parent = nCGO.transform;
         southwall.localRotation = (Quaternion.LookRotation(Vector3.zero - southwall.transform.position) * away);
         MeshFilter SWMFilter = southwall.gameObject.GetComponent<MeshFilter>();
         SkinnedMeshRenderer SWSMRenderer = southwall.gameObject.GetComponent<SkinnedMeshRenderer>();
         Matrix4x4[] WallBP = new Matrix4x4[2];
         SWMFilter.mesh.boneWeights = WallBW;
         SWSMRenderer.sharedMesh = SWMFilter.mesh;
         SWSMRenderer.bones[0].localPosition = SWMFilter.mesh.vertices[189];
         SWSMRenderer.bones[1].localPosition = SWMFilter.mesh.vertices[2];
Comment
Add comment · Show 1
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 Cyber_Defect · Apr 17, 2013 at 04:04 AM 0
Share

Not even a comment?

are boneweights included when you instantiate a previously defined object? It would seem to me they really would have to be...

1 Reply

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

Answer by Cyber_Defect · Apr 17, 2013 at 06:03 AM

I figured it out, I apparently have to set the weights of the instantiated mesh. Talk about a disgusting waste of processing.

Comment
Add comment · Show 3 · 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 Cyber_Defect · Apr 17, 2013 at 06:19 AM 0
Share

or not, I just have to set it to the already defined boneweight[] collection...

Why doesn't this go with the instantiation?

avatar image Bunny83 · Apr 17, 2013 at 06:53 AM 1
Share

I'$$anonymous$$ pretty aure it's because you use the .mesh property. It will create an instance for this $$anonymous$$eshFilter only. When you duplicate / instantiate the object it will probably use the shared$$anonymous$$esh and on this you never set the boneWeights. You have to test this yourself ;)

avatar image Cyber_Defect · Apr 18, 2013 at 04:30 AM 0
Share

Well played Bunny, I hadn't even thought of that. The API uses the mesh property and I ran with it...

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

12 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

Related Questions

Transfer bones from one Object to another (same meshes) 0 Answers

Second prefab(Clone) not finding Bones 0 Answers

Is there, or can u make a toggle button for disabling bones in Playmode? 0 Answers

Checking if object intersects? 1 Answer

Does the transform.parent hierarchy have any relationship to the bone hierarchy? 1 Answer


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