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 Pauls · Nov 22, 2012 at 09:48 PM · instantiateprefabresource.load

prefab null not instantiated: simple example not working?

Hi,

i can't instantiate my prefab, i read through the topics in the forum but i did not find any solution. Here is what i did :

-add a plane and a character to the scene,
-put them in an empty in "Hierarchy".
-Then, i created a prefab in Project, and i dragged and dropped the empty into this prefab.
-I then removed the empty from Hierarchy, and attached this script to the main camera :

 function Start () {
     //var instance : GameObject = Instantiate(Resources.Load("Prefabs/total", GameObject));
     //var instance : GameObject = Instantiate(Resources.Load("total", GameObject));
     var instance : GameObject = Instantiate(Resources.Load("total"));
     
     //instance.transform.position = Vector3.zero;
 }
 
 function Update () {
     
 }


But i have this error :

ArgumentException: The thing you want to instantiate is null.

UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) UnityEngine.Object.Instantiate (UnityEngine.Object original) I tried to put the prefab in a folder, or just in "Project", but i have got the same result. Any idea? Thanks
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
2
Best Answer

Answer by CostelloNicho · Nov 22, 2012 at 09:54 PM

Place the prefab, that you are trying to instantiate, inside a folder called Resources not Prefabs.

Here's a link: Resources.load

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 whydoidoit · Nov 22, 2012 at 10:16 PM 0
Share

Agreed or make a public variable of type Transform and assign the prefab in the Inspector and use that variable in place of the Resources.Load()

avatar image Pauls · Nov 22, 2012 at 10:19 PM 0
Share

Thanks, yes indeed! The folder's name has to be "Resources", i did not understand that, Thanks!

avatar image
0

Answer by alti · Nov 19, 2015 at 11:45 AM

For me, the issue was accidental and pretty stupid. I had applied the script to the object I wanted to do the instantiating, and then I also had it applied (not sure how or why... autopilot?) to the object that I wanted to instantiate.

So A was going to instantiate B, but on A I had the instantiate script, and I had it on B as well. The simple fix was: A was going to instantiate B. B was not going to instantiate another B, so B did not have the script. Only A had the instantiate script.

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

12 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

Related Questions

Follow and Instantiated Object 0 Answers

how to instantiate prefab with Resources.Load ? 4 Answers

Associate objects to a prefab 1 Answer

instantiating vertically 2 Answers

How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 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