Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Code that uses Color32 does not compile unless specifically using byte variables as arguments #69

Open
poi-vrc opened this issue Jan 22, 2021 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@poi-vrc
Copy link

poi-vrc commented Jan 22, 2021

Describe the bug in detail:
Consider the following code that is expected to compile correctly:

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class TestScript : UdonSharpBehaviour
{

    private Color32 color;

    void Start()
    {
        color = new Color32(0xC0, 0xD6, 0xDF, 0xFF);
    }
}

UdonSharp throws the following error stating the constructor cannot be found and fails the compilication:

[<color=#FF00FF>UdonSharp</color>] Assets\poiOS\Scripts\TestScript.cs(15,46): System.Exception: Could not find valid method for given parameters!

However, by specifically declaring byte variables and supplying into the constructor, the error no longer exists:

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class TestScript : UdonSharpBehaviour
{

    private Color32 color;

    void Start()
    {
        byte r = 0xC0;
        byte g = 0xD6;
        byte b = 0xDF;
        byte a = 0xFF;
        color = new Color32(r, g, b, a);
    }
}

I think C# seems to consider those hard-coded bytes as type Int32 instead of Byte and then auto-cast back to byte while compilication. UdonSharp seems trying to find the constructor Color32(Int32, Int32, Int32, Int32) which does not exist and fails the complication.

Expected behavior:
What was the expected result? To compile

@poi-vrc poi-vrc added the bug Something isn't working label Jan 22, 2021
@MerlinVR
Copy link
Owner

Known issue that will be fixed eventually, but it's complicated. Using an explicit cast in the constructor like new Color32((byte)0xC0, (byte)0xD6, (byte)0xDF, (byte)0xFF) also works as a workaround.

@MerlinVR MerlinVR added this to the UdonSharp 1.0 milestone Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants