Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Feature Request Calling a cloud code function from a cloud code function

Discussion in 'Cloud Code' started by DavidZobrist, May 25, 2022.

  1. DavidZobrist


    Sep 3, 2017

    I am currently writing all the cloud functions we need for a server authorative solution.

    Use Case:
    Code (CSharp):
    1.   if (await TryUpgrade(priceList,cloudSave,projectId,playerId..)) {
    2.     return true;
    3.   } else {
    4.     //TODO seperate cloud function for logging suspicious attempts
    5.     return false;
    6.   }
    Almost all of my cloud functions evaluate if an action really can be done, the client should have always known this since it has the requirements from the remote config.
    So it is suspicious that there was a call of the cloud function in this case.
    I want to log this suspicious attempts in a cloudsave entry that is also created from a cloud function.

    But I dont want to add this code to every single cloud function if I dont have to.
    So here the question:

    Can I call a cloud function from a cloud function?
    So I can have the suspicious logging function at one place and have all other functions call it?
    If It is possible would you suggest to do so or warn about it? (too many calls, even if it shouldnt happen for none cheaters)

    (awaiting the result of called cloud function would not be required)


    The examples are great and the documentation aswell even tough javascript was a new world initially.
    Overall I am pretty happy with the new services and how feedback gathered and included.
    Thank you for that!
    Last edited: May 25, 2022
    unity_Ctri likes this.
  2. Unity_AndyP


    Unity Technologies

    Jun 23, 2021
    Just to confirm, my understanding of the problem, you are wanting is to not have the same code in multiple scripts? While this isn't currently possible to do, we're looking into a file-based workflow that will enable this to be done through the editor. I will pass this over to our developers as a use case, in the meantime, you will need to put the suspicious logging function in each script you are wanting to run.

    Thanks for your feedback on the products, we are constantly trying to improve the products having the use-cases you have provided now and in the past has helped but the features are useful to you.
  3. CameronDWills


    Feb 26, 2021
    I agree with OP in that it would be useful to be able to call cloud code functions from cloud code itself. For example in my situation, I have one script that generates a list of shop items periodically, but I also have another script that creates new user data + generates a new list of shop items. Instead of having to copy/paste a whole bunch of code into my 2nd script, being able to just call it like a function would be easier and cleaner.
    Dknighter2 and DavidZobrist like this.
  4. kevin-masson


    Sep 24, 2018
    Is there any update regarding this feature? Otherwise it might be possible to achieve that with webpack maybe.

    I created a batch script that merge js files to be able to reuse code.

    Put your shared code in the Shared folder.
    Put your endpoints code in the Endpoints folder.
    Create a .bat file with the following code and run it.

    Code (CSharp):
    1. ::===============================================================
    2. :: Merge files in Endpoints/ and Shared/ to create the final backend endpoints.
    3. :: Allow to reuse code between endpoints by adding types and functions in the Shared folder.
    4. ::===============================================================
    6. @echo off
    7. setlocal enableextensions enabledelayedexpansion
    9. if exist "%~dp0Dist" rd /s /q "%~dp0Dist"
    10. if not exist "%~dp0Dist" mkdir "%~dp0Dist"
    12. for %%i in ("%~dp0Endpoints\*.js") do (
    13. Set path=%%i
    14. Set filedrive=%%~di
    15. Set filepath=%%~pi
    16. Set filename=%%~ni
    17. Set fileextension=%%~xi
    19. copy /y NUL "%~dp0Dist\!filename!.js" >NUL
    20. copy /b "%~dp0Dist\!filename!.js"+"%~dp0Shared\*.js" "%~dp0Dist\!filename!.js" >NUL
    21. copy /b "%~dp0Dist\!filename!.js"+"%~dp0Endpoints\!filename!.js" "%~dp0Dist\!filename!.js" >NUL
    22. echo !filename! Done
    23. )
    Last edited: Oct 25, 2022
  5. a125b25


    Mar 26, 2023
    Is there an update regards this feature?

    also thanks for the bash code above, I will try it.
  6. tranpd


    Aug 12, 2016
    I'm also interested in this function.
  7. pKallv


    Mar 2, 2014
  8. samg-unity


    Unity Technologies

    Mar 23, 2021
    Hi all,

    Since the initial post, we've launched CCC# modules and Observability which I believe would help resolve some of the issues of code reuse and logging suspicous activity.

    For Cloud Code scripts, there is currently some partial support for bundling via the Unity Editor (see which would allow you to include additional scripts.
    DavidZobrist likes this.