FixedListXBytes on IComponentData

So COFFEE BRAIN GAMES a long time ago said you can use FixedList on IComponentData. My main project is still largely broken. But in one of my smaller test project this no longer seems to be the case. At least not with ISystem/SystemAPI.

That sounds like a Unity bug. I wouldn’t expect anything to break because of that. A FixedList is just a fixed sized struct that treats its internal bytes like a list.

1 Like

I hope it get fixed in 1.0 preview. It also seems to affect baking.

Works fine in my tests. Even with baker.

struct:

public struct FixedListTest : IComponentData
        {
            public FixedList4096Bytes<byte> fixedList;
        }

baker:

public class FixedList_Authoring : MonoBehaviour
    {
        public int size;
       
        public class FixedList_Authoring_Baker : Baker<FixedList_Authoring>
        {
            public override void Bake(FixedList_Authoring authoring)
            {
                var comp3 = new FixedStructTest.FixedListTest();
               
                for (int i = 0; i < authoring.size; i++)
                {
                    comp3.fixedList.Add((byte) i);
                }
               
                AddComponent(comp3);
            }
        }
    }

ISystem:

foreach (var comp in SystemAPI.Query<FixedListTest>())
                {
                    for (int i = 0; i < comp.fixedList.Length; i++)
                    {
                        Debug.Log($"{i} == {comp.fixedList[i]}");
                    }
                }

Anything more specific what you’re doing?

2 Likes

I created a new blank project. Your sample gives me the same errors in visual studio.

Not sure if its just a visual studio issue. My original test also sometimes randomly gave me play time editor errors as well.

If I remove the fixedList the errors go away.

I updated to VS 2019 and I no longer got compilation errors in Bakers, but I still got them in ISystem.

Switching to VS 2022 similar result. At first intellisense was broken on 2022 but I fixed that.

So maybe it does have something to do with SystemState/ SystemAPI or maybe it is VS acting up.

After updating VS the error now appears in the editor as well and I can no longer enter play mode.

This “can’t convert …” error message usually shows up when the struct hasn’t implemented IComponentData.

If you did implement it, I can’t explain it really what’s going on.

It definably implements IComponentData. I made a bug report we will see if they can replicate.

report IN-20139

This error definitely correct and shows you actual problem. EntityManager.AddComponent adds type, not the actual component instance. If you provide component itself and not a type - use EntityManager.AddComponent__Data__
8521736--1136492--upload_2022-10-18_10-19-47.png

1 Like

Your right thanks, I actually use AddComponentData through my code. I must gave got confused with AddComponent in Bakers. Maybe AddComponent in Baker should be renamed AddComponentData.

Their is a real bug here but it only seems to be present in VS 2017.