Announcement

Collapse
No announcement yet.

CloudKit for iOS and tvOS implementation for Blueprint Only Projects.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    CloudKit for iOS and tvOS implementation for Blueprint Only Projects.

    Well I finally managed to add CloudKit functionality to my iOS game. Blueprint Only!
    It took me so long to get it working because there is no documentation at all so far on how to set up CloudKit for BP only Projects.
    Now I can play on my iPhone, get a new highscore and when I start the game on my iPad I have the same Highscore there.
    It automatically syncs my SaveGame to the newest one on the cloud every time I start the game.
    Magic.

    A little Tutorial:

    1. Create your app identifier and enable Cloudkit.
    2. Add a Container and give it the same ID as your App ID. Apple will automatically append iCloud. to the string: So your ID should look like this: iCloud.com.companyname.appname
    3. You have to make new provisioning profiles. Download and install them.
    4. Go to Project Settings - IOS - and enable cloudkit support and choose an iCloud sync file strategy. (Either always or at game start only which is what you probably want)
    5. Go to plugins and enable the online Framework Plugin which is already built in. (No documentation about that one on the internet). And restart the Editor.
    6. Launch your game to an iOS device and test if it is already working by playing the game until you Save/load. Delete the game. Reinstall. It should load the savegame you had before. Or test with multiple iOS devices.

    If it doesnt work so far, follow those steps:

    7. Head to the iCloud dashboard. Choose your App Container. Go to logs and look if your App has recently communicated with your Container.
    8. If it didnt communicate you did something wrong in the first steps I described. If it did communicate (It should have tried to fetch and query the database), then follow step 9.
    9. Go to Schema and check if there is a custom record called "file". If not create a new Record with the name "file". Then click on Indexes, add recordname and set it to be queryable.
    10. If you go to Data and query or fetch your record with type "file", then you should see an entry which was generated by your iOS device. This is your Savegame.

    Also make sure you enabled iCloud Drive on your iOS device in the Settings.

    Good so far but I really want to be able to sync it with my Apple TV because thats why I tried to implement CloudKit in the first place.
    I can see that my Apple TV is communicating with my iCloud Container and the correct User.
    TvOS is not able to save a Savegame file to a local slot like iOS can. But the event for Cloudkit to sync the savegame file is on the Blueprint Node "Load Game from Slot".

    The way Cloudkit is programmed for UE4, it only syncs the SaveGame file. (You can see how it is programmed in: /Users/Shared/Epic Games/UE_4.24/Engine/Plugins/Online/IOS/OnlineSubsystemIOS/Source/Private/OnlineUserInterfaceIOS.cpp)

    But tvOS cant save a file to a slot and therefore neither read from it. So how should Cloudkit work on tvos if it cant load or save a Savegame file?

    If someone has an idea on how to use tvOS for CloudKit sync it would be much appreciated.
    Also if you have found any way to save something on tvOS at all I would love to hear it.
    It is pretty weird that you cant save something on tvOS and there is absolutely no documentation about it on the Internet.
    Last edited by Tiefsignal; 05-03-2020, 06:54 AM. Reason: cloudkit

    #2
    Followed your steps and still not working to me. (Check attached image)
    Also enabled the plugin too.
    No data in the dashboard.

    Comment


      #3
      Originally posted by Hermyth View Post
      Followed your steps and still not working to me. (Check attached image)
      Also enabled the plugin too.
      No data in the dashboard.
      Can you confirm that your Cloudkit dashboard looks like this if you go to Schema?

      Click image for larger version

Name:	Bildschirmfoto-20200505-um-20.41.02.png
Views:	242
Size:	55.0 KB
ID:	1755651

      One thing I forgot to mention: make sure your container is in development state and your App as well. (Use the development provisioning profile and certificate)
      Or both of them in production/distribution state works as well obviously.

      Your Logs inside the Cloudkit dashboard should look like this once your phone is communicating with the cloud:

      Click image for larger version

Name:	Bildschirmfoto-20200505-um-20.48.18.png
Views:	229
Size:	104.5 KB
ID:	1755652
      And finally make sure that the Blueprint node "Load Game" is called and you set your variables afterwards from the Savegame to the variables you need in your game.

      Also I had more success with the Blueprint Node "Async Load Game". For me, this one works all the time while the "load game" node sometimes failed. (Probably due to a delay issue)

      Otherwise I don't think that I can help you any further.

      Comment


        #4
        Attached Schema.
        Container in Dev. state, and the log is empty.
        Im using distributor provision profile, because cannot upload with developer profile to the store (Testing in testflight)

        Im using async save and load node.
        The loading is manually with a button.

        Comment


          #5
          I can see that in your Schema there is no contents field as seen in my picture.
          Actually it should have created this one automatically, thats why I didn't mention it earlier but you can add it manually as well.

          So click on add field in your file.
          give it the name "contents" and select bytes.
          Hit Save.
          Select Indexes and add Index. Select contents and set it to be queryable. Add it again and set it to be sortable.
          It should now look like on my picture. in the last post.

          Also make sure that the container is in Production state since you are using a distribution provisioning profile
          like in this pictue:
          Click image for larger version

Name:	Bildschirmfoto-20200505-um-21.55.16.png
Views:	260
Size:	74.4 KB
ID:	1755694
          To do this, select the gear icon on the top right Development container and select Deploy to production.
          But only after you corrected your Schema.

          Comment


            #6
            Thanks.

            One step closer.
            Now see data on log, but got some error, and not loading back my data.

            Comment


              #7
              Great!

              Actually I had the exact same error as well but I can't tell you exactly which action fixed it for me afterwards.
              Go to Data and hit query records. Then you should see a file like I described in my first post on step 10.
              You can debug if it is the file, your app is uploading/reading by checking the modified time. It should match the time when you fired the "load game" node.

              Don't worry about the line where it says Response size 0B.
              This is still the case for me but it is working.

              Comment


                #8
                There was no generated record in the data so i added a new record. Still get that error and not see any modification when save or load in my game.
                Your database is private or public?
                Tested both. same result.
                Last edited by Hermyth; 05-06-2020, 12:43 AM.

                Comment


                  #9
                  My database is private.
                  One thing I did is named my savegame file in Ue4 (the slot name) "file" to match the record. No Idea if this did the trick.
                  I tried many things and played around with it and then it suddenly worked.
                  If f you get it to work as well, we can update the tutorial here, so it is accessible for everyone.
                  So don't give up!

                  Comment


                    #10
                    Yeah, my slot name is "file" too. Can you show a screen of your save and load nodes?
                    Are you using sync save too or just sync load?

                    Comment


                      #11
                      Okay so I tested it again and modified my Load/Save setup and now it works perfectly.
                      I realised I had an issue where it had synced when I have it installed on two devices but If you reinstalled it, it has overwritten the cloud save game with the no progress file.

                      See the attached images for my Load and Save setup.
                      Sometimes the async load game fails the first time, even if there is a cloud save. As a workaround I call it again with a little delay for 3 times. (The second time it normally loads it)
                      When it exceeds 3 attempts to load it, I then continue with my game logic and it will save a new file to the cloud. Because if it doesn't succeed in 3 attempts, I know there is no cloud save game.

                      It is definitely not a nice code but in my point of view the only way it works in Blueprints. I guess I have to learn some C++ in order to make it more efficient.
                      Attached Files
                      Last edited by Tiefsignal; 05-06-2020, 11:57 AM.

                      Comment


                        #12
                        Thanks for the pics. as i see similar normal save/load like my.

                        Don't know why not working to me, i try it more.
                        Last edited by Hermyth; 05-06-2020, 11:44 PM.

                        Comment


                          #13
                          Figured out...

                          added content and file to the users system type, now working

                          But little interesting, need to push load 2-3 times, because first time load one older saving.

                          Thanks for the help
                          Last edited by Hermyth; 05-07-2020, 01:16 AM.

                          Comment


                            #14
                            Nice!

                            For me the load node doesn't work the first time, I debugged this a lot. Mostly it loads them the second time I call it after a little delay.

                            Im glad I was able to help you.

                            If you ever try to solve this problem for tvOS let me know. I really need a solution for this.

                            Comment


                              #15
                              Sorry, i don't have apple tv
                              TvOs not need different certificate or profile maybe?

                              Comment

                              Working...
                              X