N
N
nuclear_kote2019-12-04 11:37:36
Unity
nuclear_kote, 2019-12-04 11:37:36

Where should string parameters be stored in unity entities?

public struct PlayerNameTag : IComponentData {
    public string playerName;
}

eventually crashes
ArgumentException: Components.UITags.Creation.PlayerPortraitTag contains a field of System.String, which is neither primitive nor blittable.

What to do about it and why does it occur?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
ChessMax, 2019-12-04
@nuclear_kote

It is worth considering that it NativeStringhas a length limit (there are only three options for this class: NativeString64, NativeString512and NativeString4096). Due to the poor API, working with this class as a string is not so convenient.
There are at least a couple of other solutions to the problem. The simplest is to store the strings in some kind of list, and specify the index of the string from this list in the component.
You can also create a component that implements not IComponentData, but ISharedComponentData. Such components allow you to store data of a reference type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question