Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by rpl oye · Jul 11, 2010 at 04:21 PM · gameobjectruntimecreate

create game object on the fly

hi, i am using this meshserializer from http://www.unifycommunity.com/wiki/index.php?title=MeshSerializer2 there is a loading mesh using WWW. that is getting a mesh from a url, and put it onto a gameobject.

on that webpage, the tutorial is adding a mesh filter component into an already created game object. but what i am trying to do a little bit different,

i want to create a new game object for each mesh that i downloaded using WWW. that is why i need to create a new game object for each of them.

my code so far is like this. but it is not doing what i thought it would do. the results are just two meshes instead 4 meshes. and the hierarchy is not correct either, and it has "(clone)" on created game object when i ran the game.

function Start() { var urls = new Array (); urls.Add( "http://localhost/akubz_shards/game/assets/bodyMale.data" ); urls.Add( "http://localhost/akubz_shards/game/assets/male_hair-1.data") ; urls.Add( "http://localhost/akubz_shards/game/assets/male_hair-2.data" ); urls.Add( "http://localhost/akubz_shards/game/assets/male_hair-3.data");

 log =  GameObject.Find("LogMessages").GetComponent(GUIText);
 var container =  GameObject.FindGameObjectsWithTag("charContainer");
 for(var i=0;i<urls.length;i++){
     var download = WWW(urls[i]);
     yield download;
     var mesh = MeshSerializer.ReadMeshFromWWW( download );
     if (!mesh)
     {
         log.text +=  "Failed to load mesh \n" ;
         continue;
     }
     log.text +=  "\nMesh loaded from "  + urls[i];

     var newGO=GameObject.Find("emptyCharContainer");
     Instantiate(newGO, transform.position, transform.rotation);
     var meshFilter : MeshFilter = newGO.GetComponent(MeshFilter);
    if( !meshFilter ) {
         meshFilter = newGO.AddComponent(MeshFilter);
         newGO.AddComponent("MeshRenderer"); 
         log.text += "\n  filter " + urls[i];
     }
     meshFilter.mesh = mesh;
     //make it a children of current object
     newGO.transform.parent = transform;

     log.text += "\nFinish Loading mesh from " + urls[i];
 }

}

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
4
Best Answer

Answer by Tetrad · Jul 11, 2010 at 08:05 PM

and it has "(clone)" on created game object when i ran the game.

Every time you instantiate a prefab (or game object), it'll append " (clone)" to it. You can "fix" that by setting the name yourself. Just store off the name of the object you're instantiating from, and set the .name property on the new one after you instantiate it.

Alternatively, if you just want an empty game object, you can new one off.

GameObject newEmptyGameObject = new GameObject( "gameObject name" );
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 Ashkan_gc · Jul 11, 2010 at 04:27 PM

if you want to create the object out of nothing just create a new GameObject and use AddComponent to add what you want to it. your current code seems correct. there might be a problem in your URLS or ...

note: if you add a component using AddComponent method, unity will add all required components automatically

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

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

No one has followed this question yet.

Related Questions

Why do Instantiated GameObjects Colliders only work on player i am controlling,nothing else? 2 Answers

How to add a Script to a GameObject during Runtime [2016] 3 Answers

A* Follow in runtime 0 Answers

C#: read text file and interpret as script at runtime? 1 Answer

How to pull two objects at the same time? 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