x


Switching to c# and now I can't see my custom types in the Inspector

I just switched from UnityScript to C#. I have some custom classes I instantiate within the script attached to a GameObject. When I was using US, I used to be able to see those and all their instance members in the Inspector. Now I cannot - is this an inherent limitation of using C# or can I somehow make those appear again in the Inspector?

more ▼

asked Jul 04 '11 at 12:11 PM

robinking gravatar image

robinking
756 61 68 81

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

They need to be Serializable and public. See the following snippet:

using UnityEngine;
using System;

[Serializable]
public class Pair
{
    public int x;
    public int y;
}
more ▼

answered Jul 04 '11 at 12:18 PM

Mortennobel gravatar image

Mortennobel
1.8k 10 15 34

These are the droids I'm looking for.

Jul 04 '11 at 12:29 PM robinking
(comments are locked)
10|3000 characters needed characters left

Only classes that inherit from MonoBehaviour can be attached to GaneObjects. That's a limitation of Unity, not of a specific language. In UnityScript you can omit the class construct and Unity will inherit your class automatically form MonoBehaviour. In C# you have to do that yourself. If you talk about custom data classes and you have a vatiable on a MonoBehaviour that is holding a class instance, to see it in the inspector your have to add the attribute System.Serializable.

In Unityscript all classes are implicitly serializable.

more ▼

answered Jul 04 '11 at 12:21 PM

Bunny83 gravatar image

Bunny83
45.2k 11 49 207

Yes, I'm referring to custom data classes, not the MonoBehaviour. Thanks!

Jul 04 '11 at 12:30 PM robinking
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4153
x466
x5

asked: Jul 04 '11 at 12:11 PM

Seen: 1859 times

Last Updated: Jul 04 '11 at 12:30 PM