Project to Project cloud code

Hey all, just a feature request to consider: being able to communicate between projects using cloud code.

I'm working on a multi-player game right now, client server structure where the client and server are completely different projects in unity. They share no code. I am using cloud code on both sides to do various things, but what would be really handy is if I could do something server side then send some code to the client project cloud code, which could then contact the client project. And vice versa!

Just a thought for a request. I would love to get some communication between my projects outside of the tcp connection!

Hey there, you can implement the Cloud Code API itself into your project to call the functions between the two backends, the REST API is defined here.

As for sharing the raw code between them, I wouldn't recommend it but it is technically possible via the Admin API to create, update and delete scripts programmatically as well.


Oh awesome! That is good to know!

I take it the specific line to call functions from other projects is this one:

https://cloud-code.services.api.unity.com/v1/projects/{projectId}/scripts/{scriptName}

is it possible to run this same idea through the cloud code itself? Or can I only call functions of other projects from the project itself?

Hey!
I may need a little bit of more details for your use-case, but just so you know, you can directly host CloudCode Js from the project: https://discussions.unity.com/t/898324 which would allow you to treat the CloudCode code as belonging to either project.

That said, there's nothing limiting 2 different Unity projects from linking to the same Cloud project (dashboard).
It just depends on exactly what you're trying to do. Are you trying to share code at runtime, or is it ok if its done statically?

Basically, I may be able to provide further insight with a bit of elaboration on:

if I could do something server side then send some code to the client project cloud code, which could then contact the client project

Oh that’s cool! That will likely be handy down the road! The video shows a lot of useful aspects to it. I might have to try that out some time soon, might make it easier to work with (Though making it work in the browser is pretty easy too)

That is good news! At the moment I am still trying to learn the limits of what’s available, but I have a few things I would like to try doing with cloud code.
The biggest is probably having a more secure way of sending inventory information from client to server. Right now I have the player log in with authenticate (excellent system btw) and then using Cloud Code I pull the inventory, then I have to send that inventory over a TCP message to the server. Right now its fine since I’m not working on a AAA title or anything, but it seems very easy to exploit (I can always encrypt the data to make it safer too) It seems it would be far better if that information is never sent from the client program to the server program, but instead is sent from the client Cloud Code to the server Cloud Code, or from client Cloud Code to the server directly. That way when the player spawns on the server side program, it can also grab the inventory.

A second example would be something like a minigame (Like tic tac toe) where I can run the logic of the minigame on cloud code and then send the end results to the server to tell the server that I completed the minigame.

But I am still just trying to find what is possible right now. I can do all of this through the TCP connection, but if its faster and more efficient to run it through Cloud Code then I would be more comfortable doing it that way. Not to mention I could keep the server focusing on fewer things, like just character movement.[/QUOTE]

Ah I see!
CloudCode can make web requests out to the server, so you can in principle send data from client -> cloudcode -> server.
However, CloudCode runs are meant to be short-lived so establishing a long-lived connection would not work.
I think however, the specifics on how you should set it up will really depend on the specifics of the use-case.

1 Like