Extending a Class and Using the Inspector?

Hey all,

Does anyone here know how to extend a class and still be able to use the connection that you’re extending.

Let me explain… I’m trying to extend the TextAsset class.

class DynamicTextAsset extends TextAsset {
	// Code Here...
}

But, if I assign a variable, I can’t connect a text file in the inspector. Is it possible to do this?

// I can't connect a text file to this one
var myDynamicTextAsset : DynamicTextAsset;

// But, I can connect a text file to this one
var myTextAsset : TextAsset;

Thanks,
Nathan

I stumbled into this some time back. According to it, direct subclassing is not recommended.

Can you get the same functionality by using:

class DynamicTextAsset
{
	var textAsset : TextAsset;

	function Start(){
		textAsset = gameObject.GetComponent(TextAsset);
	}

	// Code Here...
}

I wouldn’t say that direct sub-classing isn’t recommended as a whole. I think the problem here is that the inspector doesn’t check whether you’ve sub-classed off of something it knows about, it only sees your variable as being a DynamicTextAsset and dragging a TextAsset on to that just won’t work as they’re not the same (again from the Inspector’s one-level deep point of view).

In short Nathan, I don’t think you can do a drag assignment in that case, but don’t fear sub-classing in general.

And I have been updated on just how wrong I am. You should not sub-class Unity’s built-in classes as that won’t work or will be problematic. You write and sub-class off your own classes, but not the built-in Unity classes like TextAsset. My apologies for the confusion.