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 sdgd · Jan 28, 2013 at 03:55 AM · c#instantiateprefabdestroy

how to instantiate object with content prefab and not him self

first we instantiate GameObject somehow:

 public GameObject Prefab ;
 Instantiate(Prefab) as GameObject ;

than we came along that Item and we try to pick it up

 public GameObject Prefab ;
 public GameObject Player ;
 public Inventory InventoryScript ;
 void Start () {
     Player = GameObject.Find("Camera");
     InventoryScript = Player.GetComponent("Inventory") as Inventory;
 }

 void OnMouseDown () {
 InventoryScript.GivePrefab ;
 Destroy(gameObject);
 }

and in inventory GivePrefab we have content Prefab Object IF we comment Destroy(gameObject)

and how do I tell prefab item that his prefab GameObject is not him self but prefab?

it's no problem for Object that I place in scene my self as I edit the object and give it Prefab

but problem is how do I tell object that it's himself Prefab and not him self (new made)

it's kinda hard to explain

or maybe easier how do I tell what's prefab with code and not with editor?

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
1
Best Answer

Answer by sdgd · Jan 29, 2013 at 03:09 PM

Question was solved with different putted question how to instantiate prefab with Resources.Load

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

in order that Object won't be null it has to be in Project "Resources" Folder

if it doesn't work

"Resources" Folder must be created manually with Explorer (TotalCommander) in:

Default: c:\Users\UserName\Documents\New Unity Project\Assets\Resources\` for custom folder just search for New Unity Project\Assets\Resources`

I for example have it at:

 c:\Programming\unity projects\crafting house\Assets\Resources\

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
-1

Answer by cdrandin · Jan 28, 2013 at 03:58 AM

// Declare in globals public GameObject object;

// Drop prefab into the object location in the inspector in Unity's editor. When that is done,

Instanitate(object, someplace.position, Quaternion.identity); // Which creates an object based off the prefab.

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 sdgd · Jan 28, 2013 at 04:05 AM 0
Share

yes I'm telling that that creates me a item with content him self and not prefab

yeah name is same but when I delete that object as (pickup) game object doesn't exist any longer

so how do I tell PREFAB that he needs to have a PREFAB in himself when instanced and not himself ins$$anonymous$$d

IF I give Prefab manually in scene and drop prefab in to him GameObject isn't deleted but that's not instance it's $$anonymous$$anually adding to scene

I don't want to be in game near every player and instance objects ins$$anonymous$$d of them just so it'll have a prefab and not game object him self

I know it's hard to explain

avatar image sdgd · Jan 28, 2013 at 06:58 AM 0
Share

IF I want that it would work I would have to create 2 same Prefabs

let say Prefab A, B (both same size everything same) Except

Prefab A is calling Prefab B for a prefab GameObject Prefab B is calling Prefab A for a Prefab GameObject

that's the only way that I would work the way you describe but that's way too BIIIIIIIIIIG Inefficiency

because IF I call it like

Prefab A is calling Prefab A for Prefab GameObject

once it'll be Instantiate Prefab A won't call for Prefab A any longer but it'll call Him self as GameObject Witch can be deleted and I don't want to delete the

 Public GameObject Prefab ;

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

9 People are following this question.

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

Related Questions

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

How many time does a prefab takes to load?? 1 Answer

How to spawn a new prefab when the last one was destroyed?? 2 Answers

Trouble with destroying an instantiated prefab 2 Answers

help for start my project... 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