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:

  1. Head to the iCloud dashboard. Choose your App Container. Go to logs and look if your App has recently communicated with your Container.
  2. 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.
  3. 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.
  4. 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.

2 Likes

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?

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:


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.

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.

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:


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.

Thanks.

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

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.

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.

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!

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?

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.

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.

Figured out…

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

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

Thanks for the help

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.

Sorry, i don’t have apple tv:(
TvOs not need different certificate or profile maybe?

Yes I think not many people develop for tvOS so nevermind :slight_smile:
There is no documentation about it on the internet.
It is exactly the same as for iOS.
It is even the same App in App store connect.
But tvOS can’t save/load anything from the load/save blueprint nodes.

Really? I guess that means everyone needs to do a cloud save system then.

Yes this is true.
Apple wants the tvOS app to have a correspondent iOS app and that its progress is synced via iCloud.
This is also a must have in order to sign up for apple arcade. (iCloud sync and support for iOS, tvOS and macOS)
There is no persistent storage locally on an Apple TV.
See this short documentation provided by Apple.

https://developer.apple.com/library/archive/documentation/General/Conceptual/AppleTV_PG/iCloudStorage.html

Changed “async load game” to normal “load game”, now works fine. When press load button, load back the last save fine.
The save game is still the “async save game to slot” version.

The fact that tvOS can’t save/load seems to be a known Issue, although there wasn’t enough demand yet to fix it earlier.
Target Fix now is 4.25.1

See here: