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 gregtom6 · Mar 03, 2012 at 05:22 PM · meshchangeswitchreplacelooking

How can I change the lookout of an object?

Hy all! How can I change the lookout of an object? I tried to change the mesh, but only the meshfilter changed, I can see the same ingame with this code:

this.gameObject.GetComponent<MeshFilter>().mesh=m.mesh;
where m is a MeshFilter variable. Tried this too:

GameObject i=Instantiate(Resources.Load("spy",typeof(GameObject))) as GameObject;
this.gameObject.GetComponent<MeshFilter>().mesh=i.GetComponent<MeshFilter>().mesh;
this didn't achieved anything... Tried this:

    Vector3 pos=this.gameObject.transform.position;
    Vector3 rot=this.gameObject.transform.eulerAngles;
    Vector3 sc=this.gameObject.transform.localScale;
    Destroy(this.gameObject);
    GameObject g=Instantiate(Resources.Load("spy"),pos,Quaternion.identity) as GameObject;
    g.transform.localScale=new Vector3(822.7944F,822.7944F,822.7925F);
It achieved the old object has destroyed, but the new one has the same size as the original, but looks like squashed. The collider has good size too.

I don't know what should I do to change the lookout of an object... Please help me!

Comment
Add comment · Show 4
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 DGArtistsInc · Mar 03, 2012 at 05:25 PM 3
Share

what the heck do you mean by lookout?

avatar image aldonaletto · Mar 03, 2012 at 05:53 PM 0
Share

The code formatting is wrong: you should skip a blank line, place the tag <pre> in the next, paste your code and close it with a </pre> tag.
I edited your question, but editions are not currently updating due to some UA bug (they eventually appear after some time), thus I posted the whole question in this comment:

Hy all! How can I change the lookout of an object? I tried to change the mesh, but only the meshfilter changed, I can see the same ingame with this code:

 this.gameObject.GetComponent().mesh=m.mesh;

where m is a $$anonymous$$eshFilter variable. Tried this too:

 GameObject i=Instantiate(Resources.Load("spy",typeof(GameObject))) as GameObject;      this.gameObject.GetComponent().mesh=i.GetComponent().mesh;  

this didn't achieved anything... Tried this:

 Vector3 pos=this.gameObject.transform.position;
 Vector3 rot=this.gameObject.transform.eulerAngles;
 Vector3 sc=this.gameObject.transform.localScale;  
 Destroy(this.gameObject);
 GameObject g=Instantiate(Resources.Load("spy"),pos,Quaternion.identity) as GameObject;
 g.transform.localScale=new Vector3(822.7944F,822.7944F,822.7925F);  

It achieved the old object has destroyed, but the new one has the same size as the original, but looks like squashed. The collider has good size too. I don't know what should I do to change the lookout of an object... Please help me!

avatar image gregtom6 · Mar 03, 2012 at 07:36 PM 0
Share

DGArtistsInc: I mean what I can see when watching that object. For example there's a person1, and I want to see that it looks like person2 if I click on him.

avatar image gregtom6 · Mar 03, 2012 at 07:46 PM 0
Share

I have recorded the whole problem recently, you can watch that here: http://www.youtube.com/watch?v=-m$$anonymous$$j22iwTUs

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Mar 03, 2012 at 06:22 PM

You can replace the object's mesh this way:

 (GetComponent<MeshFiter>() as MeshFilter).mesh = newMesh;

If the object has a mesh collider, you must update it too:

 (GetComponent<MeshCollider>() as MeshCollider).sharedMesh = newMesh;

NOTE: Be aware that the mesh collider update is a heavy operation, and may make your game crawl like a wounded snail if done each Update!

Comment
Add comment · Show 14 · 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 gregtom6 · Mar 03, 2012 at 07:06 PM 0
Share

It says: Cannot convert type UnityEngine.$$anonymous$$eshCollider' to UnityEngine.$$anonymous$$eshFilter' via a built-in conversion

avatar image gregtom6 · Mar 03, 2012 at 07:46 PM 0
Share

I have recorded the whole problem recently, you can watch that here: http://www.youtube.com/watch?v=-m$$anonymous$$j22iwTUs

avatar image aldonaletto · Mar 03, 2012 at 09:10 PM 0
Share

It says: Cannot convert type UnityEngine.$$anonymous$$eshCollider' toUnityEngine.$$anonymous$$eshFilter' via a built-in conversion -> $$anonymous$$y fault! I just copy/pasted the first line and changed the GetComponent type, but forgot to change the casting type too. Now this asha$$anonymous$$g error has been fixed.

avatar image aldonaletto · Mar 03, 2012 at 10:30 PM 0
Share

This is an animated mesh! I don't know much about animations, but suppose you can't replace the mesh so easily in this case. You could replace the material to get simple changes like different colors or add visual details like blood stains or bullet holes. To morph the character to a different shape (like transfor$$anonymous$$g Bruce Banner in the Hulk, for instance), I suppose you should edit the model in your 3D editor and add it as an animation.

avatar image gregtom6 · Mar 04, 2012 at 10:23 AM 0
Share

Well, I'm using that script you wrote me, but I can see the same thing ingame, the mesh is the same. I think this line:

(GetComponent<$$anonymous$$eshFiter>() as $$anonymous$$eshFilter).mesh = new$$anonymous$$esh;
Should change the mesh what I can see in the game, but it just replace the meshfilter component, and I can see the same object. The collider has changed because of the second line.

Show more comments

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

7 People are following this question.

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

Related Questions

How to switch texture of several 3D objects on GUI buttons click? 1 Answer

how to swap a mesh using an array 1 Answer

How to pickup and then Change/Switch Weapons 1 Answer

Replacing the Ethan 3rd person controller mesh 2 Answers

Changing sound when walking in different areas. 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