Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity partial class does not contain a definition

Tags:

c#

unity3d

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?

like image 408
test123 Avatar asked Feb 20 '18 14:02

test123


1 Answers

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.

like image 145
Paul-Jan Avatar answered Oct 13 '22 04:10

Paul-Jan