0

I have the following problem:

  • I have a 3D engine that has their scenes, but they are not compatible with Unity.
  • But I have the metadata of this another 3D engine about everything on the scene, like: position, lights, models, light probes, physics, cameras etc...
  • I'd like to recreate this scene on Unity, but programmatically doing a parser onto this metadata I have, but not using the Unity Editor. (In the end I would have a .scene file and some created prefabs)
  • But in the same time I'd like to be able to load this created scene (from the metadata) inside the the Unity Editor (since I created it for Unity now)
  • I would like to have all the models and things created as prefabs to be able to use addressable in the future.

Is this feasible?

Maybe is there a way to create UnityYAML scene files?

felipe
  • 1,212
  • 1
  • 15
  • 27
  • 2
    It's not impossible, but it would be quite a bit of work and a lot of trial and error. You'd most likely have to build the scene in Unity anyway just to be able to see if what your converter is writing resembles how Unity handles serialization. Certainly much more work than just putting it together in the editor so you'd need to decide if you would use it enough for the time spent creating it to ever actually save time and work. – Retired Ninja Oct 20 '22 at 17:22
  • @RetiredNinja are you saying this is possible with UnitYAML scene mounting? – felipe Oct 20 '22 at 18:31
  • 1
    It's easier to instead, export your old scene's data to data files in format such as JSON or XML, then write code in Unity to import the data and recreate the scene using Instantiate(prefabs). You won't have to learn how Unity structures its scene and prefab files and it's much easier to debug the data files that you export using your own code – Trong Nguyen Oct 21 '22 at 02:49

2 Answers2

2

It looks like this would sort of be a 2 step process:

Parse your existing data structure and create them as GameObjects/Components in a scene. You should be able to do this with a regular ol' script attached to a regular GameObject. For me, I would call it something like "CustomSceneLoader". On start, read your data file, parse it, and instantiate GameObjects with that data.

From there, it looks like you can use the PrefabUtility to create new Prefabs based on the GameObjects in the scene. Maybe as part of step 1 you attach a custom Component that adds a button to the inspector that would create a Prefab from the GameObject.

For example:

PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, localPath, InteractionMode.UserAction, out prefabSuccess);
John B
  • 20,062
  • 35
  • 120
  • 170
0

As Retired Ninja mentions in the comments

UnityYAML is just based on YAML which is a raw text file format (similar to JSON)

=> Of course in theory you can generate such a file and all your content prefab and .meta files and GUIDs from scratch completely without Unity.

Which basically would mean you have to replicate this entire part of the Unity Editor.

Is this feasible?

In theory yes, but the question is, is this really worth the time and struggle? I would doubt that.


Instead depending on your exact file formats I would rather

  • Search for any plugins / external libraries that maybe already exist for this file format

  • If really non exists you again have multiple options

  • From your other engine which already understands your existing file formats export the content into a format Unity understands built-in

    For example

    • Export all meshes as FBX (-> already supports embedded materials, textures and hierarchy)
    • Export the hierarchy e.g. as a JSON or whatever text file
    • Then in Unity reconstruct the scene according to those
  • Implement your own custom Scripted Importer which can directly parse your original file(s) and convert it(them) into a scene directly within Unity.

derHugo
  • 83,094
  • 9
  • 75
  • 115