Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by chiddaan · Apr 13, 2017 at 03:03 PM · gameobjectruntimescene-loading3d modelbytes

How to load a GameObject from Byte[] in the scene on runtime?

Hi all,

I apologize for being a novice and for asking an obvious question.

I am downloading a 3D object from URL. I am using UnityWebRequest to do so. The thing is the downloaded object is in the form of System.Byte[] but I want it to be GameObject and I cannot do that on the fly, can't even cast it.

This object is an .OBJ file of 22MB.

Basically I need a a piece of code that loads an object at runtime.

Thank you, Arjun

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Apr 13, 2017 at 03:05 PM

Well, a .OBJ file is not a gameobject, so I'm not sure how the code should be expected to cast it as such.

.OBJ is a model file. That can only be imported in the editor... If you want to import it into a scene, you'll need to write (or find online and import) a script to read the format and import it into a mesh object. From there, you can apply the mesh to a MeshFilter with a MeshRenderer and have it appear in your scene.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by bkarakaya01 · Feb 12, 2019 at 12:30 PM

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEditor;
 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.UI;
 
 public class ObjDownloader : MonoBehaviour
 {
 
     private string modelName = "NAME"
     public Button download;
     public ObjImporter objImporter;
     public GameObject emptyPrefabWithMeshRenderer;
 
     // Use this for initialization
     void Start()
     {
         Debug.Log("Started");
         download.onClick.AddListener(() => StartCoroutine(ImportObject()));
     }
 
     // Update is called once per frame
     IEnumerator ImportObject()
     {
 
         WWW www = new WWW("http://Link" + modelName);
         yield return www;
 
         if (string.IsNullOrEmpty(www.error))
         {
             Debug.Log("Download Error");
         }
         else
         {
             string write_path = Application.dataPath + "/Objects/" + modelName;
 
             System.IO.File.WriteAllBytes(write_path, www.bytes);
 
             Debug.Log("Wrote to path");
         }
 
         GameObject spawnedPrefab;
 
         Mesh importedMesh = objImporter.ImportFile(Application.dataPath + "/Objects/" + modelName);
 
         spawnedPrefab = Instantiate(emptyPrefabWithMeshRenderer);
         spawnedPrefab.transform.position = new Vector3(0, 0, 0);
         spawnedPrefab.GetComponent<MeshFilter>().mesh = importedMesh;
     }
 }

And also take this script : http://wiki.unity3d.com/index.php/ObjImporter

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bkarakaya01 · Feb 12, 2019 at 12:34 PM 1
Share

I'm not sure about this %100 but it should work. This scripts will take your obj file and import it to a file in Unity. You have to create a new file in Unity. But if this doesn't work, you should import a "model.prefab" file to Unity because "model.obj" is not a game object and sometimes when you try to import your obj file you have issues with meshes.

avatar image cagdas01 bkarakaya01 · Feb 22, 2019 at 01:11 PM 0
Share

biz mi kurtaracaz dünyayı kanka , dinle şunu :)(https://www.youtube.com/watch?v=qHCcOuvfAa8)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does the gameobject brush create tiles when painting on a 2d Tilemap? 1 Answer

How to activate a component from its reference? 2 Answers

Scene Manager and Keeping Objects when Loading/Unloading + Gameogject.SetActive not working:( 0 Answers

random an image after a event ends 0 Answers

Scene Loading from Main Menu Player Transform not moving 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges