ClassTypeReference not working

Or Aviram
New Member
Registered: 2016-12-21
Posts: 2

Topic

So I had a need to make a class/type field in the Unity inspector. Luckily, I didn't have to make it myself, because I found this: https://bitbucket.org/rotorz/classtyper … -for-unity

So I happily downloaded it and put it in my project. But then I got some problems:
http://imgur.com/a/khmjC

Well, you probably want my code:

    [ClassImplements(typeof(ITest)), SerializeField]
    private ClassTypeReference test;

Keep in mind that I originally used a class, and ClassExtents (I didn't put it here because it will be confusing without seeing other parts of the project), but after a lot of testing I found it that wasn't the problem.

The weird thing is that it works with the example code. After a lot of testing, I found out that no matter what the code is, the only thing I need to change for it to work, is to change the interface in ClassImplements to the interface that came with with the asset. So of course I checked if there is something wrong with the way this is implemented. Here are the difference:

My code:

public interface ITest
{
    void DoStuff();
}

public class Test : ITest
{
    void ITest.DoStuff()
    {
        // Doin' stuff.
    }
}

public class Test2 : ITest
{
    void ITest.DoStuff()
    {
        // Doin' stuff part 2.
    }
}

Example code:

public interface IGreetingLogger {

		void LogGreeting();

	}

	public class DefaultGreetingLogger : IGreetingLogger {

		public void LogGreeting() {
			Debug.Log("Hello, World!");
		}

	}

	public class AnotherGreetingLogger : IGreetingLogger {

		public void LogGreeting() {
			Debug.Log("Greetings!");
		}

	}

But...but...they are the same (except for different methods and names, which don't (or at least shouldn't) matter)!
So neither the classes/interfaces nor the variable declarations are different, yet it works when I use the example one, but not with the one I used.
So does anyone have any idea why it is happening?

Here are a few desperate things I tried:
I tried putting the classes in namespaces. Even a namespace called "Example", which is the namespace the examples are in.
I also tried instead of making the variable private and a serialize field, I made it public.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 1

Hi

It is not clear to me what the cause of your issue is. Can you provide steps that I can follow to reproduce your issue?


Side Note: This is not the correct forum for discussions on the open source project ClassTypeReference for Unity. Please create an issue using the dedicated issue tracker for that project when reporting issues or questions.

Many thanks

Or Aviram
New Member
Registered: 2016-12-21
Posts: 2

Response 2

Lea Hayes wrote:

Hi

It is not clear to me what the cause of your issue is. Can you provide steps that I can follow to reproduce your issue?

Side Note: This is not the correct forum for discussions on the open source project ClassTypeReference for Unity. Please create an issue using the dedicated issue tracker for that project when reporting issues or questions.
Many thanks

Oh, sorry. I am new to this forum, and have barely used BitBucket (I made an account but shortly after I got accepted to using Collaborate, so it became pretty useless), so I didn't know it was there. I will post there next time.

So I was just writing the issue report, and then I needed to go to the bathroom. And I don't know why, but I always solve my problems there. Well, this was not an exception, I solved it.

I put it in folder called "Plugins", and unity separates the assemblies of "Plugins" for the others. So it didn't find it, since it was in a different assembly.
I guess there is not solution to this one except renaming the folder, since Plugins is compiled first... Well, I guess it's not that big of a problem.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 3

Aha! yes that makes sense. I am pleased that you found a solution for your issue :)