x


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!

more ▼

asked Mar 03 '12 at 05:22 PM

gregtom6 gravatar image

gregtom6
1 1 1 2

what the heck do you mean by lookout?

Mar 03 '12 at 05:25 PM DGArtistsInc

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 MeshFilter 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!

Mar 03 '12 at 05:53 PM aldonaletto

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.

Mar 03 '12 at 07:36 PM gregtom6

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

Mar 03 '12 at 07:46 PM gregtom6
(comments are locked)
10|3000 characters needed characters left

0 answers: sort newest

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!

more ▼

answered Mar 03 '12 at 06:22 PM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

It says: Cannot convert type UnityEngine.MeshCollider' toUnityEngine.MeshFilter' via a built-in conversion

Mar 03 '12 at 07:06 PM gregtom6

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

Mar 03 '12 at 07:46 PM gregtom6

It says: Cannot convert type UnityEngine.MeshCollider' toUnityEngine.MeshFilter' via a built-in conversion -> My fault! I just copy/pasted the first line and changed the GetComponent type, but forgot to change the casting type too. Now this ashaming error has been fixed.

Mar 03 '12 at 09:10 PM aldonaletto

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 transforming Bruce Banner in the Hulk, for instance), I suppose you should edit the model in your 3D editor and add it as an animation.

Mar 03 '12 at 10:30 PM aldonaletto

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() as MeshFilter).mesh = newMesh; 
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.
Mar 04 '12 at 10:23 AM gregtom6
(comments are locked)
10|3000 characters needed characters left
Be the first one to answer this question
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1364
x379
x237
x52
x7

asked: Mar 03 '12 at 05:22 PM

Seen: 903 times

Last Updated: Mar 04 '12 at 10:52 PM