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 Kprasad · Nov 08, 2011 at 07:03 PM · instantiatemultipleclone

Why does instantiation of clone cause duplicates

I have a clone that is supposed to be instantiated when conditions are met, but for some reason, when they ARE met. The clone appears more than once simultaneously. Its not constant. as some times it is only one, and other times it is four or five. Debugging through didn't give me an answer. so I'm lost

Comment
Add comment · Show 3
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 Demigiant · Nov 08, 2011 at 07:13 PM 0
Share

You should post your code for meeting the conditions and for instantiating, so we can check what's wrong.

avatar image Kprasad · Nov 08, 2011 at 07:17 PM 0
Share

sorry, this code deals with the instantiation of the unlocked item

public BuyableProperties ItemUnlocked() {

     // item not initialized or item already unlocked
     if (unlockableItem == null || !unlockableItem.isLocked)
     {
         return null;
     }

     foreach (TrophyProperties trophy in trophies)
     {
         if (trophy.isLocked)
         {
             // returns null if any trophy is still locked
             return null;
         }
     }

     // FIX$$anonymous$$E - not sure if this should be instantiating new object or getting an instance somehow...
     return (BuyableProperties)Instantiate(unlockableItem);
 }
avatar image DaveA · Nov 08, 2011 at 07:34 PM 0
Share

How is ItemUnlocked called?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Demigiant · Nov 08, 2011 at 07:46 PM

I'd need to see more code, but I assume that the ItemUnlocked method is called more than once for some reason.

First thing that comes to my mind is that you're calling it when a buttons is pressed, but you're using GetButton (which repeats while the button is pressed) instead of GetButtonDown (which is sent only the first frame the button is pressed).

Have you tried adding a trace to see how many times this method is accessed?

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 Kprasad · Nov 08, 2011 at 08:36 PM 0
Share

Its not a GetButton

 if (trophyProp.inventoryCount == 1)

     {



         GameObject collectionGameObj = GameObject.Find(mysteryBox.trophyInBox.belongsToCollection);



         if (collectionGameObj != null)

         {

             Debug.Log("Spawning unlock item");

             BuyableProperties unlockedItem = collectionGameObj.GetComponent<CollectionProperties>().ItemUnlocked();



             if (unlockedItem)

             {

                 StartCoroutine(DelayedUnlockSpawn(1.0f, unlockedItem, pos));

             }

         }

     }

this is what calls the unlocked item

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to add multiple clones of an object to a list ? Currently only 1 clone gets added. 1 Answer

Why are multiple objects being instantiated when I use clone, but not regular instantiation? 1 Answer

Cloning Problem Script 0 Answers

How can I get the x position for the left(and right) of the screen? 2 Answers

How do I make a clone of a prefab appear on the correct layer? [5.2.2f1] 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