Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 JcDenton86 · Aug 28, 2012 at 10:24 AM · prefabvuforiainstatiate

Trying to load a prefab but getting null error

I created a 3d object using Blender and imported it in Unity as .blend file.

I used this object to create a prefab as described in the Prefabs page in the Unity manual. And i believe that i did that correctly because the prefab icon is blue so it contains the object.

Now, i am trying to instatiate this prefab at runtime. I have an imageTarget and i want to clone this prefab many times and show it above that imagetarget.

The error i get is "The prefab you want to instatiate is null".

This is how i am trying to instatiate my prefab and add it as a child to the imageTarget:

 GameObject imageTarget;
 imageTarget = GameObject.Find("ImageTarget");

 Transform marker = (Transform) Instantiate(Resources.Load("Marker"), new Vector3 (XY[0], XY[1],0), Quaternion.identity);

 marker.parent = imageTarget.transform;

The script that has the above code is attached to my ImageTarget prefab.

Thanks in advance for helping! I' ve seen this question in the Answers section but i couldn't find a solution.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JcDenton86 · Aug 28, 2012 at 11:21 AM

Actually i think i figured it out..I had placed the prefab in a folder called MyPrefab. When i renamed that folder to Resources the error gone!

Anyway, thank you and appreciated your effort! It is great to be in a community like this one

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 BimSekai · Aug 28, 2012 at 10:36 AM

When you drag the prefab from your assets to the hierarchy, does it show correctly ?

Comment
Add comment · Show 1 · 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 JcDenton86 · Aug 28, 2012 at 10:40 AM 0
Share

Yes, when i drag it to the hierarchy i can see the object in the scene and the prefab is blue. Is the code above correct or there is any other way of doing this? Thank you

avatar image
0

Answer by BimSekai · Aug 28, 2012 at 11:02 AM

There is another way of doing this, using the editor, adding

public GameObject marker;

and dragging the prefab in the inspector. then you can instantiate it:

Transform myMarker = (Transform) Instantiate(marker, new Vector3 (XY[0], XY[1],0), Quaternion.identity);

Did it help you ?

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 Kryptos · Aug 28, 2012 at 11:11 AM

Did you make sure that the Marker prefab is inside a Resources folder?

Comment
Add comment · Show 3 · 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 JcDenton86 · Aug 28, 2012 at 11:16 AM 0
Share

Actually i figured it out a couple $$anonymous$$utes later and i answered my question but i can not see the answer yet..

That was the problem..I had placed the prefab in a folder called $$anonymous$$yPrefab. So when i renamed it to Resources the error gone!

Anyway, thank you and appreciated your effort! it is great to be in a community like this one.

avatar image Kryptos · Aug 28, 2012 at 11:21 AM 0
Share

Yes, you need 15 karma to have your answer posted without moderation. I will take a look at the moderation queue.

avatar image pateras · Mar 17, 2013 at 02:41 PM 0
Share

I'd give you a +1 but I don't have the karma. Just wanted to let you know that this helped me out.

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

10 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

Related Questions

How to tell the number of instantiated object 2 Answers

Instantiatied prefab runs script twice? 0 Answers

Prefab instantiated off screen problem 0 Answers

Setting the transform of an instantiated game object 1 Answer

Modifications to instance effecting all instances 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