I experienced problems when serialized a huge chunk of data into a scene.
I know, Scriptable Objects must be used in this case, that’s what Unity specifically says and that’s the main purpose of these, but in this case I cannot for whatever reason.
Three options I tested:
- A serialized huge array of floats with SerializeField attribute.
- A RFloat Texture2D with SerializeField also.
- A reference to a scriptable object instance created on runtime that stores a float[ ] inside.
[SerializeField, HideInInspector]
Texture2D texture;
[SerializeField, HideInInspector]
float[] values;
[SerializeField, HideInInspector]
ScriptableObjectData scriptableObjectValues;
class ScriptableObjectData : ScriptableObject
{
float[] values;
public ScriptableObjectData(float[] vs)
{
values = new float[vs.Length];
for(int i = 0; i < vs.Length; i++)
{
values[i] = vs[i];
}
}
}
When saving and reading the scene I get a huge component with
--- !u!114 &1612248423
MonoBehaviour:
------------ stuff I removed-------------
m_Script: {fileID: 11500000, guid: c8c11258f21500a4ba12e7615cea262d, type: 3} <-- ScriptableObj
texture: {fileID: 216413733} <--- Texture link to another section of the scene file
values: <--- Array of values
- 0.5202928
- 0.91587794
- 0.60766333
- 0.4038003
- 0.28146175
- 0.83561945
- 0.8477241
- 0.21605495
- 0.23540178
- 0.70007235
- 0.7711518
- 0.02141595
- 0.8566569
- 0.34342197
- 0.4864542
- 0.58620375
- 0.097970024
- 0.7730595
- 0.7509897
- 0.5077258
- 0.13669802
...Etc
So I’ve been told having the data on an array is terribly slow in the editor. Even though all of them have HideInInspector attribute, the data is managed by the UI anyway (??).
but having the data stored on a Texture is fast.
But the data in the texture takes as much amount as the array
The scriptable object reference is stored as another object in the scene. That’s probably not wanted either… It has to be stored in the scene.
--- !u!28 &216413733
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 2
m_Width: 500
m_Height: 500
m_CompleteImageSize: 1000000
m_MipsStripped: 0
m_TextureFormat: 18
m_MipCount: 1
m_IsReadable: 1
m_IsPreProcessed: 0
m_IgnoreMasterTextureLimit: 0
m_StreamingMipmaps: 0
m_StreamingMipmapsPriority: 0
m_VTOnly: 0
m_AlphaIsTransparency: 0
m_ImageCount: 1
m_TextureDimension: 2
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_LightmapFormat: 0
m_ColorSpace: 0
m_PlatformBlob:
image data: 1000000
_typelessdata: e931053ffa766a3fd38f1b3feabece3ec ----------------------- HUGE AMOUNT OF DATA HERE
So why is this happening? How do I avoid having it stored as a Texture2D? I want the array directly, what’s happening with the editor when opening the component? Why is it stalling all the time? All options need reserialization on change…