1

Cheers! I had a two enums, describing my entityes: Players and guns types:

public enum PlayersType {
 Scout,
 Tank
}
public enum GunsType {
 Machinegun,
 Tesla
}

I had a generic a struct generic class, and 2 realizations of it:

public class EntityType<T> where T: struct, IConvertible {
 public GameObjectType ObjectType;
}
public class PlayerEntity: EntityType<PlayersType> { }
public class TowerEntity: EntityType<GunsType> { }

And i want to create class, who has EntityType field and inherite ScriptableObject class.

I did this:

public class ObjectTypeConfig: ScriptableObject
{
 public EntityType<Enum> EntityType;
}

But its return error:

The type 'System.Enum' must be a non-nullable value type in order to use it as type parameter `T' in the generic type or method.

Does anyone know how can i create necessary field? As a result i'm want to create Class, who will be has a Array of ObjectTypeConfigs, containing Players and Towers Entitiyes.

Gilad Green
37.3k7 gold badges67 silver badges99 bronze badges
asked Oct 1, 2017 at 11:56
1
  • Did any of the following answers helped you understand and solve the problem? Commented Oct 15, 2017 at 9:02

2 Answers 2

2

You declared the property as EntityType<Enum> but EntityType has the generic constraint of EntityType<T> where T : struct.

The struct constraint means:

The type argument must be a value type. Any value type except Nullable can be specified

If You check Enum you see it is a class - and therefore can be assigned null and fails the generic constraints specified.

I suspect you want one of two:

  1. Change property to be EntityType<GunsType> or EntityType<PlayersType>
  2. Make the ObjectTypeConfig class generic too with the same constraints and then EntityType<T> EntityType
answered Oct 1, 2017 at 12:02
Sign up to request clarification or add additional context in comments.

Comments

0
public class ObjectTypeConfig<T>: ScriptableObject where T: struct, IConvertible
{
 public EntityType<T> EntityType;
}
answered Oct 1, 2017 at 11:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.