In vanilla unity, I’d do something like this for prototyping
public class GameSettings: Monobehavior{
public static GameSettings instance;
}
to store GameSettings for prototyping, while making it possible to edit certain params in the editor (like mouseSensitivity). This probably isn’t the best practice, but I was wondering what the proper ECS way to do something similar would be.
If GameSettings is class IComponentData it should be **this.**GetSingleton (extension method) as just GetSingleton has struct IComponentData restriction (will be fixed in future)
Thanks eizenhorn, I’ve been away from ecs for long time so lots has probably changed on me.
If he’s using EntityManager.GetComponentData(), doesn’t that mean it must be struct or can you get class objects the same way now?
My memory is back from when we had GetComponentObject() for objects and GetComponentData for structs still. Has this changed now?
Yes, that’s a valid point, my answer was more to warn, that GetSingleton can be used for class ICD singletons as an extension method (and itellijidea wouldn’t show you that until you will use this. for access base class). And same for EntityManager.GetComponentData as it also has the same extension method with class restriction instead of struct.
Thanks again eizenhorn. Do you know why there are separate functions for IComponentData class objects vs generic objects?
GetComponentData and GetComponentObject both return objects from ManagedComponentStore.
Do IComponentData classes have some special purpose within the api?
API evolves And as @s_schoener told me it’s just an oversight when class ICD was added and they added ticked for that task 2 months ago, and eventually, they will change that restriction. It’s not a major issue as we have an extension method, and guys working hard on other much more important things, thus we just can use that extension until they’ll fix that thing.