Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

in editor script MissingFieldException:parent

Discussion in 'Scripting' started by Ryuuguu, May 6, 2007.

  1. Ryuuguu

    Ryuuguu

    Joined:
    Apr 14, 2007
    Posts:
    391
    I get this error

    MissingFieldException: Cannot find variable parent.
    Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
    SaveTile.SaveTile () (at assets/standard assets/editor/SaveTile.js:6)

    with this editor code

    Code (csharp):
    1. @MenuItem ("GameObject/SaveTile")
    2. static function SaveTile () {
    3.     oldTile = Selection.activeTransform;
    4.     newTile = Instantiate(oldTile,oldTile.transform.localPosition,oldTile.localRotation);
    5.     tiles = GameObject.Find("Tiles");
    6.     newTile.transform.parent = tiles;
    7. }
    I don't understand how a newly instantiate transform can not have a parent field. I also tried
    newTile.parent = tiles;
    and got the same error message.
    I use similiar code writen in boo in my game and it works fine.


    Cheers,
    Grant
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    tiles is a gameObject.

    Btw. If you write var in front of your variable declarations, the compiler would infer the type and give you the error at compile time, which is probably more detailed.
    You can also put a #pragma strict in front of a script to turn off dynamic typing entirely.
     
  3. Ryuuguu

    Ryuuguu

    Joined:
    Apr 14, 2007
    Posts:
    391
    Thanks that fixed it.

    Also in case there is another Boo programmer out there (have not found one in the forums so far) This is how you do editor functions in boo
    Code (csharp):
    1. import UnityEngine
    2. import UnityEditor
    3.  
    4. class Savetile2( MonoBehaviour):
    5.     [MenuItem ("GameObject/SaveTile")]
    6.     static def  SaveTile () :
    7.         oldTile = Selection.activeTransform;
    8.         newTile = Instantiate(oldTile,oldTile.transform.localPosition,oldTile.localRotation);
    9.         tiles = GameObject.Find("Tiles");
    10.         newTile.parent = tiles.transform;
    11.  
    Cheers,
    Grant