Sigma88 / Sigma-Replacements

Handles replacement of various KSP assets
13 stars 1 forks source link

Getting this issue when i try to convert my array of color's into a texture 2d #90

Open mmartomac opened 2 years ago

mmartomac commented 2 years ago

I have an array of color's and I'm looping through it to set each value to the corresponding position on my texture2d Here's the code to convert from the array to the texture, it's in the awake() function and I have tried it in the start function as well. spriteRenderer = gameObject.GetComponent<SpriteRenderer>(); for(int i=0;i<20;i++) { for(int j=0;j<22;j++) { SpellTexture.SetPixel(i,j,shapeArray[i,j]); } } SpellTexture.Apply();

This is the error I get

UnityException: SupportsTextureFormatNative is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SpellWorks' on game object 'DefaultSpell'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.SystemInfo.SupportsTextureFormat (UnityEngine.TextureFormat format) (at <6a104889781c465ca00c12d0953583e2>:0) UnityEngine.Texture.ValidateFormat (UnityEngine.TextureFormat format) (at <6a104889781c465ca00c12d0953583e2>:0) UnityEngine.Texture2D..ctor (System.Int32 width, System.Int32 height, UnityEngine.TextureFormat textureFormat, System.Int32 mipCount, System.Boolean linear, System.IntPtr nativeTex) (at <6a104889781c465ca00c12d0953583e2>:0) UnityEngine.Texture2D..ctor (System.Int32 width, System.Int32 height) (at <6a104889781c465ca00c12d0953583e2>:0) SpellWorks..ctor () (at Assets/Scripts/SpellWorks.cs:14)

Anyone got any tips??

My-ro commented 1 year ago

Sounds like somewhere you have a declare and assign at the same time. Try something like this