Skip to content

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

@mmartomac

Description

@mmartomac

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??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions