Everytime the user uploads a local image into the game, it gives the following:
ArgumentNullException: Value cannot be null.
Parameter name: tex
The path finder works, the byte array works with the path correctly, its solely the LoadImage method that is failing. I even used the exact example in the Texture2D.LoadImage API page and it failed with the same error. This is my file:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using SFB;
public class PlayerCard : MonoBehaviour
{
private Texture2D texture;
public Button yourButton;
void Start()
{
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(imageUpload);
}
void Update()
{
}
void imageUpload()
{
var path = StandaloneFileBrowser.OpenFilePanel("Open File", "", "png", false);
var bytes = File.ReadAllBytes(path[0]);
texture.LoadImage(bytes);
GetComponent<Image>().sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2());
}
}
I dont know if im hella stupid here missing something but I have tested a series of things and I keep coming back to this.