#Cloud Code Module Missing

1 messages · Page 1 of 1 (latest)

high crypt
#

There's a few things that could be going on. If you've got the IAP package installed you should check to make sure it's not initializing UGS on your behalf, this could potentially get you pointed at the wrong default environment.

Beyond that, can you share the code you're using when you call InitializeAsync?

spiral zodiac
#

Yeah sure, its based on the example code in the docs:

#
    {
        // Call out to the RollDice endpoint in the HelloWorld module in Cloud Code
        var response = await CloudCodeService.Instance.CallModuleEndpointAsync<ResultType>("HelloWorld", "RollDice",
            new Dictionary<string, object>() { { "diceSides", 6 } });
    }
rain dirgeBOT
spiral zodiac
#
async void InitUGS()
    {
        var options = new InitializationOptions();

#if PROD
        options.SetEnvironmentName(_authenticationEnvironment_Prod);
#else
        options.SetEnvironmentName(_authenticationEnvironment_Dev);
#endif
        await UnityServices.InitializeAsync(options);
    }
#

IAP package is not installed yet.

high crypt
#

Hmm, let's take a look at the Module code as well I guess, not seeing anything obvious here so far

spiral zodiac
#

One "thing" which is a litte bit confusing atm is that the project started 2 years ago and we are using VS2019 unti today and the Cloud Code module is using Visual Studio 2022 because .Net is not supporting VS2019 anymore. So we will switch code probably also to 2022, but atm for testing both VS version are used at the same time.

#

The module code is also based on the example..

high crypt
#

Have you verified you're taking the 'dev' codepath on initialization when you run?

spiral zodiac
#

yes

#

You can see it also in VS, because the non used code path is gray

#

And I receive all other data in the dev environment from authentication and analytics.

high crypt
#

And just to understand the tooling involved, you're using the deployment window to push the code into the service?

spiral zodiac
#

exactly

#

I can also see the module in the cloud dashboard in the dev environment.

high crypt
#

Ok I'd try a couple things, make a trivial change to your cloud code module code, and make sure it redeploys

See what happens if you rename that module, does everything show up where you'd expect it to

spiral zodiac
#

@high crypt Well, after a lot of sweating and tears I was able to track down the problem a bit further. I was experimenting with the modules, putting in compiler errors to see if the deployer compiles and uploads the right module, etc.. Installing and unstalling different .net sdk versions and so on.
Finally I was replacing the
AuthenticationService.Instance.ProcessAuthenticationTokens(AccessToken, SessionToken) method for signing in with the
AuthenticationService.Instance.SignInAnonymouslyAsync(); method and it worked..

#

I am using Custom ID for authentication by sending a GUID for the actual player to my backend server which authorizes the player by using the Custom ID API for getting the Authentication Access Tokens and sending them to the client which signs the player in by using the ProcessAuthenticationTokens() Method. This works fine, I can see the regarding players in the PlayerManagement dashboard in the cloud, see the regarding analytics events, etc.

#

But Cloud Code doesnt seem to work this way.

spiral zodiac
#

@high crypt Sorry for bothering you, but do you have any suggestions what I am doing wrong or how to solve this?

high crypt
#

I can think of some more tests to run to try and narrow things down, have you tried calling into another service using your custom authentication? (Something like Cloud Save should be a simple test). That'd help us narrow down if it's a service specific problem or something to do with the authentication itself.

#

The environment that's used is typically embedded in the auth token, it's possible that's being lost in translation somewhere along the way, I'm not familiar with the Custom ID APIs but you could check to see if you could/should be passing environment in as an optional parameter to those

spiral zodiac
#

As I said the custom authentication works fine with analytics and authentication, the analytics event appear in the right environment for the according players. Players (which are also created by Custom ID when Unity sees them the first time) also show up in the right environment of the Player Management dashboard in the cloud. I can try it with Cloud Safe today, too, but not sure how it should help me solving the issue with Cloud Code.

high crypt
grizzled kettle
#

im also having this issue but only on cold starts @high crypt

high crypt
grizzled kettle
#

mine is a little different. nothing to do with auth for me (i think)

high crypt
#

@grizzled kettle yes likely something else, we can start a separate thread if you want to work through something

grizzled kettle
#

ok pleas

spiral zodiac
#

Hey @high crypt , thanks for the answer, but I am a little bit confused now. I am using my backend server to authenticate my users with a custom id. So here is what I do:

  • I authenticate my backend api by using the Token Exchange API: https://services.api.unity.com/auth/v1/token-exchange with the projectId and an ENVIRONMENTID as parameters!
  • I check if the AccessToken is valid or needs to be refreshed before authenticating a user.
  • Then I authenticate a user by using the CustomID Api (https://player-auth.services.api.unity.com/v1/projects/{ProjectId}/authentication/server/custom-id) sending the AccessToken as Bearer in the AuthenticationHeader and my CustomID (GUID) together with the "signInOnly=false" flag in the body, so that if the user didn't exists before it will be created in the Unity Backend now.
  • After a successful authentication I will send the response including the idToken and sessionToken back to the client which requested the authentication.
  • The client uses then the idToken and SessionToken to sign the user in by calling AuthenticationService.Instance.ProcessAuthenticationTokens(AccessToken, SessionToken);

What confuses me is the Api you mentioned is to get the idToken, but I am already getting the idToken from the CustomID API, I don't understand why and where I need to use the Api you mentioned?
And I also wonder why I have to use the environmentID for the API authentication in the backend when I have to set it again. Thanks for your patience and help!

spiral zodiac
#

@high crypt Did you had some time looking at this, because I am really not sure how to continue with this.

high crypt
#

Then I authenticate a user by using the CustomID Api
When you do this, try adding a UnityEnvironment header to your request

@honest shore do you see anything amiss here?

honest shore
#

Hi, I just tested this and confirmed that for the CustomId operation, it does not use the environment id obtained from the token-exchange jwt token.

You need to provide to environment name in the UnityEnvironment header as part of the Custom Id operation.
This is how all operations work for authentication as far as environment goes.

spiral zodiac
#

@high crypt and @honest shore Thank you for you help, I just tested it by myself and can also confirm that adding the Enivronment to the header does the trick! It's working now! Just for the records if someone else search for this.. adding this line to your C# .net code CustomId Authentication request fixes it:
httpClient.DefaultRequestHeaders.Add("UnityEnvironment","dev");

#

Thank you very much for your help!