Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Platiniumekk · Jul 01, 2017 at 12:21 AM · gameobjectobjects

Copy of Item without instanticade on scene.

Hi, i have little problem. I tryed to make equipment but i dont know how to make copy of GameObject.

 public GameObject[] item = new GameObject[35];
 
 public void adding(GameObject obj)
     {
         bool found = false;
         for(int i = 0; i<35; i++)
         {
             if(item[i] == null)
             {
                 item[i] = obj;
                 Destroy(obj);
                 found = true;
                 break;
             }
         }
         if (found == false)
         {
             obj.transform.position = GetComponent<CharacterControll>().cam.transform.position + GetComponent<CharacterControll>().cam.transform.forward;
             obj.transform.parent = null;
         }
     }

i want to have copy of Item but without instanticade on scene. But i got message "Missing Object".

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
0

Answer by Razputin · Jul 01, 2017 at 06:14 AM

Make it a prefab and drop it in your script.

I think that's what you're asking.

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 Platiniumekk · Jul 01, 2017 at 03:48 PM 0
Share

nope, i wanna copy item from scene and destroy original. Statistics of item are not static, so i have to make copy.

avatar image
0

Answer by NoseKills · Jul 01, 2017 at 04:40 PM

GameObjects have a transform component that defines their position and rotation in the scene and in the scene hierarchy and they can optionally have other components like renderers that define how they are drawn on the screen.

If your items often exist in the game in a way that these things are irrlevant/not needed/not wanted (all you need is their values) they probably shouldn't be stored as GameObjects.

If you want to tweak item values in inspector, you could use ScriptableObjects as the source of your data and instantiate those to make copies or depending on your needs, even create some factory methods (e.g. in the ScriptableObject) that pull the needed values from the SO into a normal C# class instance and make copies of those C# classes (for example the C# class could have a constructor that takes in the SriptableObject and pulls some values from it).

When you need to show your items somewhere in the game, you could make and use a MonoBehaviour that can take your SO/item data class and configure itself graphically using the SO's data

The unity tutorial explains how you can easily create scriptableObjects into your project. You can make multiple assets using the same "Item" ScriptableObject that you program. Then just name the created asset files "sword", "shield" etc. in the project view, tweak the values and drag those objects to wherever you need references to sword or shield stats.

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

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

Related Questions

How to set GameObject's component to an instance of an object 0 Answers

Objects are slowing game 2 Answers

Changing tagged objects in script 1 Answer

Cubes are through inside each other? 0 Answers

Make object move randomly 2D 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