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
0
Question by Aeron0 · Jun 20, 2013 at 10:03 PM · model

Help with my first fbx model in Unity via Script!

All I want to do is make a GameObject variable in my custom class, assign my fbx model to the gameobject variable and be able to render my model to the screen all without using the drag and drop Inspector. I want to do all this in script.

I have some experience in c# and scripting in Unity GUI. I also a played around with 3d models in Unity via the Inspector. What i don't have experience in, is creating gameobjects and assigning 3d models in Unity using scripts only.

For example I have imported a .fbx model in Unity via the Inspector and rendered to the screen and done basic things as rotate it in a script. But i need help loading my model via script and not use the inspector.

I have a fbx model that has 2 meshes and 2 textures. When i drag my model from the assets folder to the Hierarchy it auto creates a parent object that just has a transform with 2 children objects that have my 2 meshes and textures that make up the model. I can render to screen and control all of this via the parent gameobject's transform with no problems.

But if i avoid the drag and drop Inspector method and try to do this in script via myGameObject = Resources.Load("myModel") as GameObject;

i get that error "It has no render" if i try to do anything with myGameObject.

I check to see if it was including the children via:

Debug.Log ("child:" +myGameObject.transform.childCount);

It did as Debug.Log was printing out the value 2. But when I try the render myGameObject in the script I get an error saying "It has no render". Well it's true, it does not have a render, only a transform, but the children do have meshfilter and render.

What confuses me is I don't get this error when I drag and drop my model in the Hierarchy from the assets folder.

Comment
Add comment · Show 2
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 iwaldrop · Jun 20, 2013 at 10:22 PM 0
Share

In short, Unity is creating GameObjects with $$anonymous$$eshFilters and $$anonymous$$eshRenderers, setting the $$anonymous$$eshFilters, and assigning $$anonymous$$aterials. You can do all the same things in script, but it is far simpler to create Prefabs and just instantiate them as is.

To create a prefab, just drag a Hierarchy object to the Project folder. If its in Resources, it's available via Resources.Load, but you can also assign Prefabs as GameObject variables in the inspector (fyi).

avatar image Aeron0 · Jun 20, 2013 at 11:36 PM 0
Share

I made my fbx model a prefab and added it to my Resource folder. I'm still getting the error message "It has no render" whenever I try to do something with it such as a transform.

I would like to note that my prefab in the resource folder has a Hierarchy. alt text

In the script i have

 GameObject myObject;
 
 
 void Start () 
 {
   myObject = Resources.Load("myPrefab") as GameObject;
   myObject.transform.position = myVector;
 
 
 
 }


project.png (4.3 kB)

0 Replies

· Add your reply
  • Sort: 

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

15 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Triangle Mesh Problem 2 Answers

Why is my model jumping to position 0,0,0? 1 Answer

How to Change Parenting while in game? C# 1 Answer

Polygons, NURBs & Sub-Divisions 2 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