Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Problem with Boo syntactic macro

Discussion in 'Scripting' started by Daniel_Brauer, Apr 11, 2011.

  1. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I'd like to put all of my serialized fields into a block, and not have to write [SerializeField] explicitly for each one. Does anyone know how to do this with a macro? I tried this, but although it compiles it gives me errors when I try to use it. Here is the macro definition:
    Code (csharp):
    1. macro serializeFields:
    2.     for statement in serializeFields.Body.Statements:
    3.         yield [|
    4.             [SerializeField]
    5.             $statement
    6.         |]
    Here is me trying to use it:
    Code (csharp):
    1. class Test:
    2.     serializeFields:
    3.         m_single = 1f
    And here is the error:
    Code (csharp):
    1. BCE0034: Expressions in statements must only be executed for their side-effects.
    If I try and print the AST branch that I'm yielding, it looks fine to me:
    Code (csharp):
    1. [SerializeField]
    2. m_single = 1.0F
    Any ideas?