Home > Mobile >  How to create a scene without the Unity 3D editor
How to create a scene without the Unity 3D editor

Time:10-21

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?

CodePudding user response:

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);

CodePudding user response:

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.

  • Related