0

Using Unity 5.4 beta with Hololens, setting a class within a namespace disables some UnityEngine functionality.

If I declare a class, it all works fine. If I wrap it inside a namespace, classes don't see each other, even within the same namespace or with the using addition.

Making a class MonoBehaviour, I can drag and drop it onto a game object, if I wrap that class inside a namespace, Unity complains that it is not a MB or it has issue so it cannot be dragged.

Does anyone have similar issue? Just asking before reporting bugs since 5.4 is still beta.

3
  • Have no idea - did you try calling this classes like Namespace.MyClass ? Commented Jul 4, 2016 at 16:24
  • Can you show us an example. We're using namespaces extensively in our code and have no such issues. Do you have optional parameters anywhere by any chance? Commented Jul 4, 2016 at 16:44
  • I'll post some code tomorrow while at office but there is little about it. I have not tried to call with explicit namespace, will try that one in case. Commented Jul 4, 2016 at 21:10

2 Answers 2

1

Classes don't see each other because you are not importing them or accessing them through their namespace. To access anything in a namespace, you must import the namespace or call the namespace followed by the class name. Check below for both examples.

Class with namespace:

namespace MyANameSpace
{
    public class A
    {

    }
}

In order to see class A, you have to import it with the using keyword.

using MyANameSpace;
public class B : MonoBehaviour
{
    A a;

    // Use this for initialization
    void Start()
    {
        a = new A();
    }
}

Another method is to access them directly through the namespace.

public class B : MonoBehaviour
{
    MyANameSpace.A a;

    // Use this for initialization
    void Start()
    {
        a = new MyANameSpace.A();
    }
}

If this does not solve your problem, then you have to post your code. That's likely not a bug.

Sign up to request clarification or add additional context in comments.

2 Comments

I happen to have done it properly. This is working fine in 5.3, I am using 5.4 (beta). Will check again tomorrow in case it fixed itself or I was doing something wrong but I tried in many ways and it would always end up that if one is in namespace then fine, if two classes are in different custom namespaces then issue.
@Everts I am using 5.4 (beta) too. It works. Dude post your code when you get home. You likely messed up somewhere.
0

I managed to figure out what I think is happening. Here is what I had:

namespace Company.Hololens
{
    public enum GazeState
    {
        None = -1, NoHit, Hit
    }
    public class CursorEventArg : EventArgs
    {

    }
    public class CursorController : Singleton<CursorController>
    {
    }
}

and it seems as if Unity does not like the order of class declaration. Pushing the EventArg down to the end of the script and it goes fine.

Not sure if this should be considered a bug, I have never seen any mention of class declaration order. Declaring an interface on top is fine though.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.