Did Boo Property Macros break in the final releases?

I have been working in Boo for a while now, and after installing the latest version of Unity I am getting errors for all my Boo Property fields. For example:

[Property (name)] public _name as string

#spits out a couple of BCE0005 Unknown Identifier and BCE0024 UnityEngine.PropertyAttribute error

This did not happen in Unity 4 Beta 11, but started happening in the final releases. I tested 4.0.f3 and 4.0.f7 and both have these errors. Is it something to do with Monodevelop or Unity changing how we can use built in Boo macros?

I’m having this problem too.

I was going to start my own thread, but after doing some investigation I discovered my problem is related to this one.

I just finished making an editor extension that adds autosave to unity, so I got started on some actual game coding. The default property attribute that boo uses works in Editor scripts (I’m using it in the scripts I wrote for my autosave extension) but causes compiler errors when UnityEngine is imported so:

import UnityEditor

class Triplet:

	[Property(x)]
	private _X as single = -1
	private _Y as single = -1
	private _Z as single = -1

	public def asUnityVector():
		return Vector3(_X,_Y,_Z)

works when placed in Assets/Editor folder, but the script:

import UnityEngine

class Triplet:

	[Property(x)]
	private _X as single = -1
	private _Y as single = -1
	private _Z as single = -1

	public def asUnityVector():
		return Vector3(_X,_Y,_Z)

Gives compiler error: “Triplet.boo(5,15): BCE0005: Unknown identifier: ‘x’.” followed by: “Triplet.boo(5,6): BCE0024: The type ‘UnityEngine.PropertyAttribute’ does not have a visible constructor that matches the argument list ‘(error)’.” When placed in the Assets/Standard Assets/Character Controllers/Sources/Scripts folder.

When I tried importing UnityEngine in my Editor version of the script I got the same errors, after checking the docs I see that UnityEngine defines an attribute with a similar name [PropertyAttribute] but uses it for something different from boo. Does anyone know a workaround, or am I stuck writing out my property get/set methods by hand?

After delving into boo macros and attributes in search for a solution to an unrelated problem I ended up discovering the easy work-around for this problem. Built-in boo macros and attributes are defined in the Boo.Lang.Extensions namespace, so prefixing your Property attribute with the namespace name will fix the naming conflict problem:

//works even when UnityEngine is imported
[Boo.Lang.Extensions.Property(x)]
private x as int

Putting the full namespace everywhere is tedious so I went one step further and made my own custom attribute that inherits from the built in Property attribute and has the same constructors and just passes on it’s arguments to the super class:

import System
import Boo.Lang.Compiler.Ast

class BooPropertyAttribute(PropertyAttribute):
	public def constructor(propertyName as ReferenceExpression):
		super(propertyName)

	public def constructor(propertyNameAndType as TryCastExpression):
		super(propertyNameAndType)

	public def constructor(propertyName as ReferenceExpression, setPreCondition as Expression):
		super(propertyName,setPreCondition)

If you compile the above code into a .dll file, and include the .dll in your assets folder, then you can add the .dll as a reference in your current project and use:

[BooProperty(x)]

when you want to use a boo style Property attribute and it should work without errors, even when UnityEngine is imported, since it no longer has the same name as UnityEngine.Property.

P.S. I must voice my recommendation to my fellow boo programmers that might be thinking of using custom macros/attributes to download the boo source code from: here and peek inside, since I doubt I could have figured this out from online information sources. Also I discovered some built in macros and attributes that I never knew existed :stuck_out_tongue:

Any Update on this issue? I’m having the same trouble.

Thank you so much Ghost314! You really saved me there :slight_smile: