Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
7
Question by sdgd · Jan 29, 2013 at 05:57 AM · c#instantiateprefabresource.loadoafa

how to instantiate prefab with Resources.Load ?

I've went several times through this Unity Manual it's always missing as GameObject on end and even if I correct that error it always thinks my instance is Null how do I instantiate a Prefab? so I don't need to duplicate every prefab?

what I want to achive is: Prefab in instantiated Object and not GameObject as him self

 GameObject instance = Instantiate(Resources.Load("Hatchet"));

 GameObject instance = Instantiate(Resources.Load("Hatchet", typeof(GameObject))) as GameObject;
 
 ArgumentException: The thing you want to instantiate is null.
 UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:71)
 UnityEngine.Object.Instantiate (UnityEngine.Object original) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:58)
 Inventory.Start () (at Assets/Player/Inventory.cs:38)


Comment
Add comment · Show 12
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 robertbu · Jan 29, 2013 at 07:23 AM 0
Share

What problem are you trying to solve by loading the prefab from Resources?

avatar image sdgd · Jan 29, 2013 at 07:38 AM 0
Share

yes so it understands what's prefab when it's in scene so it doesn't point to it self but prefab

avatar image Berenger · Jan 29, 2013 at 08:08 AM 2
Share

$$anonymous$$ake sure the prefab is in a folder called "Resources", in your asset folder. Not an answer, as you probably did it already.

avatar image Mikilo · Jan 29, 2013 at 08:39 AM 0
Share

Hi, You can take a look at PrefabUtility.InstantiatePrefab. That could helps you.

avatar image whydoidoit · Jan 29, 2013 at 09:25 AM 1
Share

@$$anonymous$$ikilo a Resources.Load (that works) creates a copy of the resource loaded (they aren't cached), then Instantiate would make a second copy. We can only see a bit of the OPs code, but if that happened more than once it would waste resources.

Show more comments

4 Replies

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

Answer by appearance · Jan 29, 2013 at 11:45 AM

Make sure that "Hatchet.prefab" file exists in Resources folder and 'Resources' folder exists in 'Assets' folder. It should work then.

Comment
Add comment · Show 4 · 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 sdgd · Jan 29, 2013 at 02:56 PM 0
Share

finally thanks

ammm... next problem if I end up with 500 prefabs that needs to be created and deleted and read the deleted prefab witch I can now

how can I keep track of them only in 1 folder but thanks a bunch for now

it works I didn't have Resources folder in my unity project

not even the smallest logic didn't brought me there

c:\Program$$anonymous$$g\unity projects\crafting house\Assets\Resources\

avatar image appearance · Jan 30, 2013 at 05:58 AM 2
Share

You can store your prefabs in subfolders inside 'Resources' folder. (Ex: Assets/Resources/category1/hatchet.prefab). In this case you can load it as Instantiate (Resources.Load ("Category1/Hatchet") as GameObject);

You can create as many folders / sub-folders inside 'Resources' folder to maintain your prefab hierarchy.

avatar image commodore · Mar 06, 2015 at 11:13 PM 1
Share
  Instantiate (Resources.Load ("Category1/Hatchet") as GameObject);
 

Should be

  Instantiate (Resources.Load ("Category1/Hatchet")) as GameObject;
avatar image vselockov · Jul 21, 2021 at 01:08 PM 0
Share

lol this is the best answer :D I tried to change my code, looked into documentation, tried unity.object type but the problem was that I moved wrong prefab to resources folder so script couldn't find it

avatar image
1

Answer by komal2992 · Jan 25, 2017 at 01:05 PM

make sure your folder name is Resources. then create a prefab...

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 aliffhatim · Nov 21, 2018 at 09:40 AM

Hi sorry for asking can u solve my problem , i think almost same problem as him, this is the error code


ArgumentException: The Object you want to instantiate is null. UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:381) UnityEngine.Object.Instantiate (UnityEngine.Object original) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:240) Sample.ImageTarget_DynamicLoad_ManualPlay.LoadVideo () (at Assets/EasyAR/Scripts/ImageTarget_DynamicLoad_ManualPlay.cs:40) Sample.ImageTarget_DynamicLoad_ManualPlay.Start () (at Assets/EasyAR/Scripts/ImageTarget_DynamicLoad_ManualPlay.cs:35)


The code on the line are respectively: cs 35 . LoadVideo() cs 40 . GameObject subGameObject = Instantiate(Resources.Load("TransparentVideo", typeof(GameObject))) as GameObject;

how can I solve this. Thank 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 Volorf · Jul 15, 2020 at 07:38 PM

Try to preload the prefab before you instantiate it. You can use Start() method.

 GameObject _go;
 
 void Start() 
 {
      // Make sure that you put your prefab in the folder Assets/Resources
      _go = Resources.Load("MyPrefab") as GameObject;
 }
 
 void Update()
 {
      if (Input.GetMouseButtonDown(0))
      {
           Instantiate(_go, transform.position + Vector3.up, Quaternion.identity);
      }
 }


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

18 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 avatar image avatar image avatar image

Related Questions

Follow and Instantiated Object 0 Answers

Check if object is destroyed on level load, if so instantiate prefab? 1 Answer

how to instantiate object with content prefab and not him self 2 Answers

Bullet Instantiation 1 Answer

how to set custom parameters to GameObjects and access them? 1 Answer


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