#Baking and using AddComponent complaining about non-nullable value type

1 messages · Page 1 of 1 (latest)

valid pecan
#

So I'm using a Baker to bake a MonoBehaviour into an Entity component to place onto an Entity.

My IComponentData I am trying to add to my entity contains a struct I wrote called StaticsPayload.

Inside StaticsPayload is an array of another struct I wrote called Static.

Finally, Static is a struct that contains 4 int variables.

For some reason, when I try to use AddComponent during the baking process it complains

The type MyStructType must be a non-nullable value type, along with all fields at any level of nesting

If I comment out StaticsPayload then this error goes away. If I go into StaticsPayload and change my array of Static variables to not be an array, this error goes away.

Is there some reason having a struct with an array of structs is causing this error to happen? I don't see anything about my structs that would cause a nullable value type at any level of nesting.

#

Maybe the array needs to be a NativeArray?

devout badger
#

arrays are managed

valid pecan
#

that seems crazy to me somehow, but since NativeArray exists I guess that makes sense

devout badger
#

you can use fixed arrays

#

though their data types are quite limited annoyingly

#

or things like FixedListN<T>

maiden brook
valid pecan
#

I figured it was a fundamental C# issue. I wonder why they architected C# that way. I am sure they had their reasons.

devout badger
#

Because you probably don't want to have to manually allocate and dispose your arrays!

valid pecan
#

So garbage collection reasons then

devout badger
#

yes it's managed by the GC

valid pecan
#

I guess that IS what managed means thinksmart