Hello,
I have a problem: I’m creating a small robot walking on the ground (now, for testing, I’m using a trivial “translate”, to “slide” it on the ground).
I do the following steps:
I send Raycast on the ground (from the robot).
Grab distance from ground. If the robot is too much near from the ground, then I set the robot Y-axis to:
hit.point.y + myMesh.bounds.center.y
“hit” is RaycastHit instanced object;
The problem is I cannot get “myMesh” (Mesh instance of my Mesh). My GameObject contains the mesh “g0”, and I tried as follows:
GetComponent(MeshFilter).mesh;
But I get the error:
Parto…
UnityEngine.Debug:Log(Object)
UnityEngine.MonoBehaviour:print(Object) (at C:\builds\unity-branches-2.5.x\unity-2.5.x\Runtime\Export\Generated\BaseClass.cs:799)
jsMove:Start() (at Assets\BOT_HERCULES\jsMove.js:95)
(Filename: Assets/BOT_HERCULES/jsMove.js Line: 95)
GetComponent requires that the requested component inherits from Component or MonoBehaviour.
You used GetComponent(Mesh) which does not inherit from Component.
UnityEngine.GameObject:GetComponentByName(String)
UnityEngine.GameObject:GetComponentByName(String)
UnityEngine.GameObject:GetComponent(String) (at C:\builds\unity-branches-2.5.x\unity-2.5.x\Runtime\Export\Generated\BaseClass.cs:137)
UnityEngine.Component:GetComponent(String) (at C:\builds\unity-branches-2.5.x\unity-2.5.x\Runtime\Export\Generated\BaseClass.cs:464)
jsMove:Start() (at Assets\BOT_HERCULES\jsMove.js:96)
[…..\Runtime\Mono\MonoExportUtility.cpp line 133]
(Filename: Assets/BOT_HERCULES/jsMove.js Line: 96)
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, System.Object[ ] args, Boo.Lang.Runtime.DispatcherFactory factory) [0x00000]
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[ ] args, Boo.Lang.Runtime.DispatcherFactory factory) [0x00000]
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
jsMove.Start () (at Assets\BOT_HERCULES\jsMove.js:96)
(Filename: Assets/BOT_HERCULES/jsMove.js Line: 96)
NullReferenceException
jsMove.Update () (at Assets\BOT_HERCULES\jsMove.js:113)
(Filename: Assets/BOT_HERCULES/jsMove.js Line: 113)
NullReferenceException
jsMove.Update () (at Assets\BOT_HERCULES\jsMove.js:113)
(Filename: Assets/BOT_HERCULES/jsMove.js Line: 113)
NullReferenceException
jsMove.Update () (at Assets\BOT_HERCULES\jsMove.js:113)
(Filename: Assets/BOT_HERCULES/jsMove.js Line: 113)
Can you tell me how can I get a reference to the Mesh where the scripting is running into, so I could get its “bounds”?
Thank you for your help!
Eric5h5
September 27, 2009, 6:45pm
2
GetComponent returns a Component, .mesh is not a property of a Component, so you must cast the type appropriately.
(GetComponent(MeshFilter) as MeshFilter).mesh;
–Eric
Thank you! It works perfectly.
One question more: pplease can you explain me what is “MeshFilter”, since the manual is not so light?
I only understood it is related to Asset (mesh template).
THank you!