5
votes

I have 2 partial classes in main/editor projects unity, but unity show me error message "error CS1061: Type 'Engine.Test' does not contain a definition for 'radius' and no extension method 'radius' of type 'Engine.Test' could be found. Are you missing an assembly reference?"

./Assets/Test.cs (in main project):

namespace Engine {

    public partial class Test : MonoBehaviour {

        [SerializeField]
        private float radius = 1f;

    }

}

./Assets/Editor/TestEditor.cs (in project Editor):

namespace Engine {

    public partial class Test {

        private void OnDrawGizmosSelected() {
            Gizmos.color = new Color(1f, 1f, 0f, 0.3f);
            Gizmos.DrawSphere(new Vector3(0,0,0), radius); // in "this" context field "radius" not found
        }

    }

}

What am i doing wrong?

1
@vc74, sorry, yes, this typo, "Engine") | fixed - test123
Why are you using the partial class? What are you trying to achieve? Maybe more of a comment for CodeReview as opposed to SO, but I'd argue that partial class definitions should only really be used for separate pieces of logic. It seems like an obstacle having to jump from one partial to the other in order to understand them both. - Flater
@Eddge No, partial types can have different definitions so long as they are the same type (class) and are labeled partial. See this link - Sudsy1002
@Sudsy1002 ahh thanks. - AresCaelum

1 Answers

7
votes

Unity Editor files are included in a separate C# project, and end up in a separate assembly. You cannot define partial classes over assembly boundaries.