NativeContainers that contain interfaces.

So, say you have IGeneric, a GenericStruct, and a GenericStruct2, both of which implement IGeneric. It’s possible to have a NativeArray but not NativeArray to hold both GenericStruct and GenericStruct2. Why? Is there any workaround? I tried using generics with type constraints but that still only lets me declare a list of either GenericStruct or GenericStruct2 which is functionally the same as just declaring a list of either of those types.

Is there some way to use generics in reverse? For instance, generics let you say “This containers (one) type MUST BE a struct and IGeneric” where I’d like to say “This container can only contain things that are type struct and generic.” if that makes sense…

I guess as an additional question: Is there ANY way to pass code into a job? I’ve tried lambdas, interfaces, actions… etc. Basically I want to be able to hand a job some code and have it run it. The closest I’ve gotten to getting it to work is interfaces, so that’s the focus of this post. If there’s a better way of doing things let me know.

I think that FunctionPointer is what you are looking for

Try looking at this post and bellow.

It explain a bit how to inject code into a job by using generics and a struct implementing an interface.

I used it in the skill system that is discussed in that thread and it works great. (my code is not yet ready to publish, soon :wink: )

Native containers can’t store interface because they reserves memory for each element and interface implementations can have different sizes. Moreover, it can’t be passed by value.

1 Like

@Micz84 Yeah, that makes sense. This means I’m gonna have to seriously refactor things but that’s okay.