This worked in 2020.1b7 and prior. I did not need to set meshes to read/write enabled. This is intended. I dont want these meshes to be read/write enabled at runtime. I only want to modify the mesh on import.
I just updated to 2020.1b12 and now my meshes wont import. I get the following error:
Not allowed to access colors on mesh 'MyMesh [Linear]' (isReadable is false; Read/Write must be enabled in import settings)
UnityEngine.Mesh:get_colors()
ModelLinearCorrection:OnPostprocessModel(GameObject)
Note this did not happen in b7 and prior.
This is the onlyway I have found to modify mesh on import. If this change is intended, there is no longer any way to edit meshes during Edit time without setting them to read/write enabled for runtime purposes. So I am hoping this is just a regression and will be fixed! And if not, I hope there is a âproperâ way to edit meshes at âedit timeâ without enabling read/write for runtime.
This happens when reading from textures as well, our texture batcher reads from them at edit time and now it breaks.
We have to mark them as read/write, then run the game in the editor, then run the scripts, then stop play mode, then turn off read/write.
Very broken.
What about 2019.4.x though? No mention there or in 2019.3.xâs release notes, yet it broke some time after 2019.3.7 (see #3). The new method is definitely missing in 2019.4.1.
I canât find anything âAcquireReadOnlyMeshDataâ related in the public issue track (link), so Unity staff would be needed to answer if a bugfix is planned for 2019.4.
Hey thanks for looking in to this! Just to clarify, this fix will allow us to both read and write into the Mesh instance being imported?
Iâm not just interested in reading data, I also need to write data into the imported mesh. I think we got a little off track here and seem to only be focusing on the read aspect.
No, the fix is specific to meshes. If youâre experiencing issues on that end, it would be great if you could submit a bug report with reproduction steps. It doesnât look like this is a known issue.
Bug reporter just crashes, if it gets as far as loading then it always complains the description is not long enough and I end up having to fill it with lorem ipsum.
Here is a full reproduction script, itâs used for a crude atlas generator.
Assign textures, watch it fail to read them in the editor, even with read/write on.
You have to enter playmode for this to run and you have to have read/write on.
It should work at edit time without read/write on.
using System.IO;
using UnityEngine;
[CreateAssetMenu(fileName = "AtlasCreator", menuName = "Game/AtlasCreator", order = 1)]
public class AtlasCreator : ScriptableObject
{
public Texture2D[] sprites;
[Header("Settings")]
public int size = 2048;
public int tileSize = 32;
public int tilesX = 12;
public int tilesY = 16;
public string atlasName = "GroundAtlas";
[ContextMenu("CreateAtlas")]
public void CreateAtlas()
{
var x = 0;
var y = 0;
var targetTexture = new Texture2D(size, size, TextureFormat.RGBA32, false);
for (int i = 0; i < sprites.Length; i ++)
{
for (int yy = 0; yy < tilesX; yy += 2)
{
for (int xx = 0; xx < tilesY; xx += 2 )
{
var pixels = sprites[i].GetPixels(xx * tileSize, yy * tileSize, tileSize, tileSize);
targetTexture.SetPixels(x * tileSize, targetTexture.height - (y+1) * tileSize, tileSize, tileSize, pixels);
x++;
if (x >= size / tileSize)
{
x = 0;
y++;
}
}
}
}
File.WriteAllBytes($"{Application.dataPath}/Game/Ground/{atlasName}.png", targetTexture.EncodeToPNG());
}
}
Hello SevenPointRed! Iâve managed to make a repro project in 2020.1.0b13, but was unable to reproduce the issue. While it does seem that Atlas operation doesnât work without having Read/Write enabled on a texture, the same behaviour is present in 2018.4 as well, so itâs not a regression.
After setting Read/Write enabled on the textures, I was able to create the atlas in both Editor and play mode so it might be that the issue got fixed in later 2020.1 versions, or there is more to the bug that just that. I have attached my project.
Thanks for checking, thatâs odd as it always worked for us in previous 2018 versions, though we never touched the latest 2018.4, I donât remember the last version we used. I will check through git as well, im sure we had some versions of 2019 where it worked.