Weird bug with Watson Credentials in Unity

2019-08-17 02:57发布

问题:

I'm trying to implement Watson Assistant into Unity.

When I create a new Credentials object using the username, password, and serviceUrl as arguments. The serviceUrl is set correctly, but the username and password remain null. I use the same exact code for other services but specifically with this script I get this bug.

//Properties
[SerializeField]
private string _username;
[SerializeField]
private string _password;
[SerializeField]
private string _serviceUrl;

private void CreateService() {
        //Credentials
        Debug.Log(_username);
        Debug.Log(_password);
        Debug.Log(_serviceUrl);

        Credentials credentials = new Credentials(_username, _password, _serviceUrl);

        Debug.Log(credentials.Username);
        Debug.Log(credentials.Password);
        Debug.Log(credentials.Url);

        //Service
        //service = new Assistant(credentials);
}

OUTPUT

username
password
serviceUrl

null
null
serviceUrl

I was getting the same issue with the example script.

回答1:

All the IBM Watson services on IBM Cloud changed from username / password to IAM (identity and access management) authentication. Hence, when you use older code that has not been adapted, it could happen that it looks for username and password in the credentials object.



回答2:

I tried this code and it works for me. Are you adding your username/passsword/serviceUrl in the inspector or are you adding directly in this script? The values may be overwritten by empty fields in the inspector.



回答3:

After updating the Watson SDK, I no longer get this bug in any of the scripts. Still not sure exactly what the issue was in the old version. The properties were indeed set in the inspector, and they seemed to set the values fine until it was added to the object.

It could have been the fact that I wasn't using IAM, however using the username and password in the updated version seems to work fine.