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
6
Question by Extrakun · Sep 08, 2010 at 10:49 AM · mesh

How do change the mesh of a game object

I have a game-object which would 'transform' to another mesh when a button is pressed. How does I assign the new mesh with one that I have already loaded into the Unity3D project structure?

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
7
Best Answer

Answer by AliAzin · Sep 08, 2010 at 11:59 AM

you can change MeshFilter.mesh .

Comment
Add comment · Show 4 · 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 silverwizard · Oct 21, 2013 at 12:54 PM 1
Share

Sorry to resurrect an old thread, but I'm facing a problem with that... The prefab I am taking the mesh FRO$$anonymous$$ ends up losing the mesh. The mesh (a cube) gets applied to an object on the stage (a cylinder). At first glance, it seems to work, i.e. I can see the mesh changing. However, the cube mesh is ERASED from the cube prefab permanently - until I manually reassign a cubic mesh in the Inspector window. How can I prevent this from happening?

Here is the code I am using: using UnityEngine; using System.Collections;

 public class cameraCheck : $$anonymous$$onoBehaviour {
     
     public GameObject initialObject;
     public GameObject swapObject;
         
     $$anonymous$$esh initial$$anonymous$$esh;
     $$anonymous$$esh swap$$anonymous$$esh;
     
     GameObject theTarget;
 
     // Use this for initialization
     void Start () {
         
         theTarget = initialObject;
         
         initial$$anonymous$$esh = initialObject.GetComponent<$$anonymous$$eshFilter>().mesh;
         swap$$anonymous$$esh = swapObject.GetComponent<$$anonymous$$eshFilter>().mesh;
             
         theTarget.GetComponent<$$anonymous$$eshFilter>().mesh = swap$$anonymous$$esh;
     }

}

avatar image meat5000 ♦ silverwizard · Oct 21, 2013 at 01:03 PM 0
Share

$$anonymous$$ake a backup. These functions $$anonymous$$eshFilter.mesh and $$anonymous$$eshFilter.shared$$anonymous$$esh can permanently change an asset.

$$anonymous$$ake sure that it ends with a mesh loaded in and not No mesh and make sure you aren't Destroying it in the prefab.

Perhaps submit this as a new question.

avatar image silverwizard silverwizard · Oct 21, 2013 at 02:22 PM 0
Share

yes, but in this case it's the mesh of the prefab I am copying FRO$$anonymous$$ that gets destroyed. Please note that I am not "writing" anything to that object. I am just storing it in a variable, and then I am applying the variable to the other object. Why is it that the mesh I copied gets removed? It's analogous to copying (not moving) a file and then finding out that it no longer exists in the original location.

avatar image eric_unity45 silverwizard · Sep 21, 2018 at 02:29 AM 0
Share

Sorry to Necro your necro but I didn't see a satisfactory answer. Because you didn't clone it you assigned it. If you look up instantiate it is the unity equivalent of object.clone the = assigns it does not create equivalent copies. SendInTheClones.GetComponent().mesh = Instantiate(objOriginal.GetComponent().mesh); Tested it with a raw cube and turned it into a little white piggy without deleting the original

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

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

Constraining GameObject Movement Inside a Mesh Volume 0 Answers

calculate normals 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 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