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 Kag359six · Jan 19, 2012 at 07:16 PM · guierrorinstantiateprefabinventory

Instantiating object from inventory

I almost have a function inventory for my project, but when i try deploying my object through my inventory, it says "the prefab you want to instantiate is null" even though the object its looking for in my assets is indeed a prefab with the same name and is blue. heres the code:

 function OnGUI() {
 
 //var openSubMenu = false;
 
 inventoryStyle.normal.background = guiBackground;
 
     if(iWasPressed && timesPressed == 1)
     {
         Time.timeScale = 0;
         inventoryOpen = true;
         GUI.Box(Rect(guiX, guiY, guiWidth, guiHeight), "inventory", inventoryStyle);
         if(GUI.Button(Rect(15,30,75,75), slot1) && slot1Empty == false)
         {
             openSubMenu = true;
         }
         if(GUI.Button(Rect(160,30,75,75), slot2) && slot2Empty == false)
         {
             openSubMenu = true;
         }
         
         if(openSubMenu == true)
         {
             GUI.Box(Rect((Screen.width - 150)/2, (Screen.height - 100)/2, 150, 100), "drop object", subMenuStyle);
             if(GUI.Button(Rect((Screen.width - 125)/2, (Screen.height - 25)/2, 50,50), "Yes"))
             {
                 Debug.Log(deployObject.name + "is the instancing object");
                 var droppedObject = Instantiate(Resources.Load(deployObject.name), Vector3(transform.position.x, transform.position.y, transform.position.z + 5),
                 Quaternion.identity);
                 openSubMenu = false;
             }
             
             if(GUI.Button(Rect((Screen.width + 25)/2, (Screen.height - 25)/2, 50,50), "No"))
             {
                 openSubMenu = false;
             }
         }    
     }
     
     if(timesPressed < 1 | timesPressed > 1)
     {
         inventoryOpen = false;
         Time.timeScale = 1;
     }
 
 }
 
 function ObjectImageSwap() {
 
 if(selectedObject.name == "testObject1")
 {
     slot1Empty = false;
     slot1 = testImage;
     if(slot1 == testImage)
     {
         Debug.Log("slot1 should be test image");
         deployObject = gameObject.Find("testObject1");
     }
 }
 
 if(selectedObject.name == "testObject2")
 {
     slot2Empty = false;
     slot2 = testImage2;
     if(slot2 == testImage2)
     {
         Debug.Log("slot2 should be test image2");
         deployObject = gameObject.Find("testObject2");
     }
 }
 
 }
 
 if(!slot1)
 {
     slot1 = defaultImage;
     slot1Empty = true; 
 }
 
 if(slot1)
 {
     slot1Empty = false;
 }
 
 if(slot1 == defaultImage)
 {
     slot1Empty = true;
 }
 
 if(!slot2)
 {
     slot2 = defaultImage;
     slot2Empty = true;
 }
 
 if(slot2 == defaultImage)
 {
     slot2Empty = true;
 }
 
 if(slot2 == testImage2)
 {
     deployObject = gameObject.Find("testObject2");
 }



Comment
Add comment · Show 6
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 Kag359six · Jan 19, 2012 at 07:35 PM 0
Share

its basically telling me that there is an object to instantiate. however when i call the instantiate line of code, it returns saying the prefab is null.

avatar image Kag359six · Jan 19, 2012 at 07:37 PM 0
Share

basically, my code says when a ray hits an object, return the name, assign that name with an image for the inventory. if i click that button with the image of an object, i want it to instantiate it by finding a prefab with the name of that object.

avatar image Kag359six · Jan 19, 2012 at 07:47 PM 0
Share

it displayed the object name which was whatever deployobject is, and then it said "is the instancing object". so it would say "testObject1 is the instancing object" is that what you're asking?

avatar image Kag359six · Jan 19, 2012 at 07:58 PM 0
Share

well this is basically a test run, and im trying to make the script as dynamic and self sufficent as i can. so, even though there is already the object in the scene, im just trying to instantiate it again in the inventory, since i have to click on that object anyways for it to be in my inventory. im trying your suggestion now

avatar image Kag359six · Jan 19, 2012 at 08:00 PM 0
Share

it didnt work unfortunately. its the same as i had it before, except deployObject is now a string from the start. its hard to explain... it looks for the gameObject through gameObject.find in the beginning when the object is in the scene, and then IDEALLY i want to destroy after i figure out how to instantiate it

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

New GUI and Inventory problem. 1 Answer

Inventory Instantiation problem 1 Answer

Error : Missing GUILayout.EndScrollView/EndVertical/EndHorizontal? UnityEditor.DockArea:OnGUI() 1 Answer

How to skip certain objects in List, in a for loop? GUI related. 1 Answer

Setting the parent of a transform which resides in a prefab error 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