Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
5
Question by CyberBotX · Mar 14, 2010 at 03:57 AM · meshgraphicsskin

Replace a Skinned Mesh in a character with a new Skinned Mesh

To help illustrate my problem, I have the following PDF that I created: 1

Basically, CharacterPrefab is based off of CharacterFBX and is what is in the scene of the game. ReplacementPrefab is based off of ReplacementFBX. I want to take MeshObj1 of the character, and replace it with the MeshObj of the replacement, as I do not need to duplicate the skeleton already on the character. I need to know the best way to do so.

I tried to use Resources.Load() to get a GameObject of the FBX with it's hierarchy, and then using Find() on it's transform to get just the mesh and then using it's gameObject property with Instantiate() to create a new copy. I then tried to set it's parent transform to the transform of the character, but that seemed to do nothing, the duplicate just floats where it was copied, and the copy does not get placed with the character even when I use transform.position and transform.rotation in the Instantiate() call.

I also tried earlier to not bother with trying to find the mesh's object and just set the parent transform of the base GameObject to the character's transform. This made it follow the character, but it was not placed correctly (just a little higher than it should've been) and ignored the skeleton when moving. Looking in the hierarchy during gameplay shows that the full object was placed on the character, which is why I think it's not following the character's bones.

If there is some other way I should be going about this, I would like to know. What I really need is an easy and/or sure-fire way to swap out a single mesh out of X number of meshes from a character. I can't place a list of GameObject transforms on a script as we have no idea how many replacement meshes we will eventually have.

So in the end, my question would be this: What is the best (and probably easiest) way to replace a single mesh in a character that has multiple meshes?

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 Ricardo · Apr 12, 2010 at 08:55 PM 1
Share

Just wanted to give you some kudos on a very well detailed question. Cheers!

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Ony · Mar 14, 2010 at 11:38 PM

Try something like this:

Assuming your replacement mesh is in the Resources folder...


theMainMesh = GameObject.FindWithTag("sometag");

var Swapper : SkinnedMeshRenderer = theMainMesh.GetComponent(SkinnedMeshRenderer);

SwapMesh = Resources.Load("the_Replacement_Mesh_filename", Mesh); Swapper.sharedMesh = SwapMesh;

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 CyberBotX · Mar 16, 2010 at 12:18 AM 0
Share

I did try this, and what happens is that the replaced mesh looks like the original but with pieces missing. Even trying to store a copy of the original mesh back into the shared$$anonymous$$esh didn't help.

avatar image Ippokratis · May 05, 2011 at 02:27 PM 0
Share

you should take care of the shared mesh and the material/materials actually

avatar image kablammyman · Jun 22, 2011 at 06:19 PM 0
Share

I'm also experiencing the same problem. I tried various methods, I have asked around the net for help, but this seems to be a problem that many others have had, but nobody knows what to do. I'm only writing here to "bump" the question and to also get some information from somebody who knows this.

Also, I want to add that yes, you can move the verts in the mesh via the update method, but you can NOT give the shared mesh a new mesh to render, even if it will work as a normal mesh. It will have the same problems as the OP has listed. Also, giving a mesh that has more verts than the original will crash unity.

avatar image
0

Answer by MichiealO · Sep 21, 2013 at 06:34 PM

Well, one of the Ideas that I had, was to create added objects (clothing etc.,) and just add them to the character. That makes it to where one doesn't need to swap out the mesh, if the main mesh is the basis of all the others. Then, I changed out the material on the mesh... This seemed to work well for the primary material, but things start to go a bit hinky when doing secondary materials. My main character has two materials in its mesh, and I can change the primary just fine, add in any number of clothing/props/etc., but if I swap the secondary material out, it fails, and swaps the primary instead. The last resort option that I have is to just swap the player out with another prefab, that has been set up with the secondary material preset, and just use the material swap and prop swap to do the rest. This might work well, for answering this question, as the prefabs can be instantiated in code, and as long as you find the player (usually named something like "Player(Clone)" if you've instantiated a prefab named Player at runtime). those are the options & ideas that I came up with. Hope that it helps.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Assigning imported mesh from script 1 Answer

Using MeshFilter.mesh with static ground plane makes object turn into a plane. 0 Answers

Drawing a mesh with Graphics.DrawMeshNow 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting a mesh's triangles and vertices from file causes distortion. 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