- Home /
Other
Export Function
Is it possible to add a exporting function to a game in unity. Just like blender has which asks the format and the address and name for exporting. If so then how should I implement this in my game.
What are you trying to export? You could use the UI element called 'dropdown', fill it with items containing the different formats etc, and run the right method depending on what the user chose.
Sorry but this question is way to vague. What exactly do you want to export from your game?
Of course in general everything is possible, it's just a matter of how much efford it takes. Unity is a game engine and as such does not have any direct support for generating asset files with just a couple of exceptions. For example Unity can generate png or jpeg files out of a texture. However Unity does not have any support for model files. So you need a third party library that can generate your desired file format or code it yourself.
Without more information about what you want to export, nobody can answer this question and we are going to close it. Please ask clear and detailed questions.
@Bunny83 This might be a basic question but are there different levels of moderators? How do you close a question that made it through moderation, but seems to be very vague or a duplicate etc.
Yes there are. At the end of the FAQs there's a list of what rights you have at which karma level. I'm not sure if that list is actually up to date. Though I passed the 10k a long time ago ^^.
ps: If you spot actual unrelated spam / advertisement Please make sure you report the post as such. Posts in the reported list can be easily removed which will also revert the bumping and we can easily suspend the user.
Sorry I wasn't clear before. I want to export models. $$anonymous$$y game is basically a model making software but unlike blender the user will get premade parts and can join them to make a whole model. I haven't made this yet, just wanted to get the export function out of the way.
Programs like blender can export in user-chosen formats such as .obj, .stl etc. These file formats take vertices, tris and normals and convert it into a file containing that data. Unless you have knowledge of how to create these files, you shouldn't step any further.
If you do know how to format your data into a widely accepted file format for meshes, you can get the data of your model by accessing the tris, verts, normals, and text coords of your mesh through the mesh filter. For example:
Vector3[] verts = GetComponent<$$anonymous$$eshFilter>().mesh.vertices;
etc. @eraban I did write a program a while ago that converts a mesh into an stl file, but I wouldn't recommend writing your own algorithms to do that.
Okay thanks for the advice. Looks like I have too less knowledge about this.
Well exporting models isn't that simple depending on the target format. Watch out when you use premade parts. If you got those parts from the assetstore, the assetstore license does not allow any usage of the assets outside of a Unity project. So if you let users export things you don't have a full-rights licence on you could get into legal trouble.
You should update your question with more details instead of posting comments. You still haven'T mentioned any concrete target format. How you would export files also highly depends on your target platform, WebGL, Android, iOS and standalone builds work vastly different when it comes to file handling and exporting. Again, more details.
We've written collectively about 3 times as much as you have in your question ^^.
Answer by BastianUrbach · Jan 29, 2021 at 03:48 PM
It depends on your requirements. Generating a basic .obj file from a Unity mesh is actually remarkably simple:
void ExportObj(Mesh mesh, string path) {
var actualCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
var thread = System.Threading.Thread.CurrentThread;
thread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
var stream = new System.IO.FileStream(path, FileMode.CreateNew);
var writer = new System.IO.StreamWriter(stream, System.Text.Encoding.UTF8);
writer.WriteLine($"o {mesh.name}");
foreach (var vertex in mesh.vertices) {
writer.WriteLine($"v {vertex.x} {vertex.y} {vertex.z}");
}
foreach (var uv in mesh.uv) {
writer.WriteLine($"vt {uv.x} {uv.y}");
}
foreach (var normal in mesh.normals) {
writer.WriteLine($"vn {normal.x} {normal.y} {normal.z}");
}
var triangles = mesh.triangles;
for (int i = 0; i < triangles.Length; i += 3) {
var a = triangles[i + 0] + 1;
var b = triangles[i + 1] + 1;
var c = triangles[i + 2] + 1;
writer.WriteLine($"f {a}/{a}/{a} {b}/{b}/{b} {c}/{c}/{c}");
}
writer.Flush();
writer.Close();
thread.CurrentCulture = actualCulture;
}
Answer by wolfgraphicsLLC · Jan 29, 2021 at 01:11 PM
hello I was just reading and I have to say yes unity doe have function to export models. in the package manager is an fbx pack so far thats the only one I know of.
Follow this Question
Related Questions
How can i hide the c#/js code from my asset on the market? 1 Answer
Why won't my exported FBX file work in Unity? 2 Answers
Exporting terrain objects with FBX?,Is there a way to export a terrain object to FBX format? 1 Answer
Can't correctly expot MagicaVoxel object to Unity 0 Answers
exporting sdk from unity3d 2 Answers