I have a common class GameObject and several of its child classes. Each of them has its own additional variables. When saving a game, I need to save all objects of these classes.
I had the idea to save information about each object in JSON and then save these JSONs to an array inside the SaveGame object, but Unreal Engine does not provide an opportunity to work with JSON. I also had a thought to serialize these objects, but the Unreal Engine does not do this either.
What should I do?
Unreal Engine 4.18.3 Blueprint
If you're using only blueprints you can't write JSON or handle files, and that's the big limit of blueprints. You may find some plugin in the marketplace that writes JSON files with blueprints (like this) but I suggest you to start coding in c++ because it's very difficult to handle dictionaries in blueprints.
So the problem is that you want to use JSON but Unreal Engine generally uses a DataAsset object type , there are some plugins but in general you could
create your own parser and generate USTRUCTs on compilation time.
However if you are using JSON to pass server information a parser is needed to a struct.
On the other hand , you could in theory use UnrealJS to pass the JSON as a JS object instead of using BPS
The VaRest plugin lets you read JSON from a URL or from a local file. Not sure about the local one since I'm using a custom file reader implemented with FFileHelper.
If you're going that far, my suggestion is to not use the SaveGame object at all. Just create it locally and read it whenever necessary. It gives you more control, in my opinion.
Related
Is Model class a must have for flutter application? If so, where is it comes into the picture in a simple database fetch, insert, update scenario? I am using supabase for my application. Can't I fetch data from database table and display in a page (I am using Provider for State Management)? Similarly, can't I insert data by directly reading from widgets?
It's not necessarily a must have and there are always work arounds, however it could save you a lot of code because you'll be repeating yourself often without it, especially if you're making a bunch of API calls and you need to serialize the data to a JSON readable format.
If you fetch it from your database I assume it'll be in a JSON format, from which you'll have to deserialize it. Personally, I think your project will be much easier with models classes.
There are plenty of extensions that can help you with this. For example, search for Dart Data Class Generator.
I am trying Flutter in a small App for my company. I come from the C# world.
My Scenario
I get data from a server (json). The objects (possibly thousands of them) i get can have any number/type of properties, which are only known at runtime.
What am i looking for?
Basically i am looking for an alternative to C#'s DataSet in Flutter.
About DataSet the documentation says:
is an in-memory cache of data retrieved from a data source
What do i have so far?
I have looked through the web without finding anything that answers my question. The only approach i came up with was using a Map-like approach to store the json items, but i hope there is something else in Dart i can use since C# also has Dictionary, but DataSet is very rich compared to it, see the docu on DataSet...
NOTE: In C# i used to use also a Reflection-Emit approach to crate classes at runtime once i got the data, but since i am also developing for iOS, that approach is not allowed (JIT not allowed)
I'm creating an app for iPhone, and I want it to load data from an external file (from an URL in a server), to display the hints.
I have read several tutorials, but I don't know yet what is more convenient for me:
Do I use CoreData?
Do I create a .sql file and I try to do queries inside the code of my app?
Do I use a .txt file and try to parse it?
Do I use a .xml file?
I have to say I'm quite lost at this point, and I really don't know what would be more effective, easy to write (code). And I don't how to access to a file that is in a server and not in the folder of the app itself.
If your loading data from an external server take a look at Rest Kit. It allows you to map an API to objects that are backed by Core Data. http://restkit.org/
Personally I would use CoreData simply because you get a lot of power out of the box right from Core Data, instead of trying to deal with raw sql queries or parsing data.
Another option if your looking for the simplest way to grab a file from a server and map it to an object is to look at .plists for example:
NSDictionary *data = [dict initWithContentsOfURL:[NSURL URLWithString:#"http://server.com/data.plist"]];
Although be careful with that call though because its not asynchronous, and if the file is large and call is made from the Main thread it will block the application.
The best way to implement database on iPhone SDK is to use CORE Data.
- It prevents you to write long sql scripts to fetch & write data in db.
- Easy Implementation.
- Excellent UI to simulate.
- portable
- Can upgrade later if any enhancement required after some time.
So I would like to suggest you to save your data using Core Data. you need to fetch your data from server & call simple methods to save it into App DB using Core data. You even dont need to do much manipulation into it.
Following are some Nice Links for some tutorials:
http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/
http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/
I’m an experienced developer, but new to Mac. I just don’t want to go down one path only to find out that I made some fundamental error or incorrect assumption later on.
I want to ultimately build and sell an iPhone app using Core Data. The app will be free with content available through in-app purchase. Here is what I want to be able to do:
OPTION 1
Build a Mac OS X utility app that points to the same Core Data object model, but has its own “master” database.
Populate the master database using the Mac app.
Export a subset of the master data from the Mac app to a flat file (XML?) that is a subset of the master data.
When the user purchases that data, download from the cloud and import that data into the local iPhone data store.
Number 2 should be easy enough. I have read about the XML Parser that should help me with #4. I need help with #1 and 3.
For #1, I can’t figure out how I can maintain one object model for both apps with Xcode. That data model must accept model versioning. Do I just create two Projects, one Mac and one iPhone, and point them both to the same .xcdatamodel file and the magic happens for me?
For #3, is there any sample code that someone can share that will iterate through an array of objects to create the XML?
OPTION 2
Another option I am considering was discussed below. Instead of worrying about import/export, simply create individual sql files for each set of new or updated data.
I could maintain a separate "metadata" database that has information about the individual sql files that are available to the app.
Then, I can dynamically access the individual SQL files from the local documents directory. This is similar to an iBooks model where the sql files equate to individual books.
I'm thinking I could have only two active database connections at a time... one for the metadata and the other for the specific "book". I am not sure if this will scale to many (tens or hundreds) sql files, however.
Any help is appreciated!
Jon
UPDATE: I just saw the answer from Marcus Zarra at:
Removing and adding persistent stores to a core data application
It sounds like Option 2 is a bad idea.
For (1), you can use the same object model in both apps. Indeed, if you use the same Core Data generated store, you are required to do so. Simply, include the same model file in both apps. In Xcode, the easiest way to do this is to put the model file external to the project folders of each project and then add the model file without copying it to the project folder. This will ensure that both apps use the same model file for every build.
For (3), you need to first create an "export" persistent store using the same model as the reference store and add it to the reference context. In the model, create an "Export" configuration. Create a subentity for every entity in the model but do not change any attributes or relationships. Assign those entities to the Export configuration.
You will need to add a "Clone" method to each ManagedObject subclass for the reference entities. When triggered, the method will return a subentity populated with the reference objects attributes and relationships (the relationship objects will be cloned as well.)
Be aware that cloning an object graph is recursive and can use a lot of memory.
When you save, because you assigned them to the "Export" configuration, all the cloned export entities and their relationships will be saved to the export store. You will have cloned not only the objects but the related object graph.
Include the model and the export store in the iPhone app. Write the app to make use of the export entities only. It will never notice the absence of any reference objects.
For (4), I wouldn't mess around with using XML or exporting the data outside of core data at all. I would just use the export Core Data SQL store created in (3) and be done with it.
You can give a NSManagedObjectContext instance and instance of NSPersistentStoreCoordinator. This class has options allowing you to specify a file location for sotring data and a format (SQLite, Binary, or XML)
How do you plan to actually transfer data from Mac to iPhone? Is this something you do during development, or something people do during daily use? If the latter, you are probably better off building decoupled export/import into your app right away. So the Mac would serialize data into XML or JSON, push it somewhere in the cloud (not sure if local network/bonjour transfer is easier or useful, cloud is more universal), and iPhone fetches the data and deserializes it into the local schema/repository. You should not plan to work on the SQL layer with Core Data. Different platforms may use a different storage backend.
I am considering backing up data from an iPhone application using the Google App Engine (GAE) - I was also considering using Python to build a RESTful app to deal with incoming/outgoing data.
On the client side I am using Core Data to store the information I wish to back up, and retrieve using the GAE.
I was wondering whether there were any good tutorials/resources on carrying out the above or whether this is perhaps something that others have tried to implement.
Any advice, or pointers, would be most welcome.
An open-source implementation of a REST server for GAE-python is available here.
I know nothing about core-data, but I you could easily store the objects in GAE if you are able to serialize them as binary or xml.
Binary objects up to 1Mb can be stored as BlobProperty, and strings as TextProperty.
There is also a Blobstore API for objects up to 50 megabytes.
If you want to store your data on a server (or sync it) then you want to go through a intermediary format. I personally recommend JSON as it can be used with Core Data easily. Since you can retrieve a dictionary of all the values in an object it is trivial to convert that diction to JSON data and push it over the wire to your server. Your server can then retrieve that JSON data and translate it into whatever format the server wants to store it in.
Do you want to map your core data objects onto GAE datastore objects? If so, this could be tricky. As you say, you would have to implement the server logic with python or Java, and you r iPhone objects are in Objective-C. You would need some scheme to serialize / deserialize them.
An easier approach, if all you wanted GAE for was backup, would be to serialize the Core data objects and store them as blobs with key-value pairs in GAE.
I'm not aware of any similar approaches so I'll be keeping an eye on this post.