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 muhammadamir3175 · Apr 25, 2020 at 01:41 AM · respawnduplicaterespawninginitiate

How to create a duplicate of an object after a specific time with the same starting properties?

Please read carefully and help me

Now I have a visible bullet which is the child of a gun and its position is attached to the end point of the gun(as the player moves the gun, the bullet also moves) now when the player clicks, the bullet is released from the point and is no longer the child of the gun(I had to detach the parent/child relationship because the bullet was still moving with the mouse cursor when it was in the air). Now the bullet hits the target(it is a big bullet so it is visible), as soon as it hits the target I do not want to bother the released bullet anymore, all I need is the copy of the same bullet but in a way that it was all in the very beginning, i-e a new bullet reattaches to the parent, it appears exactly at the point of its parent and again moves with the cursor of the parent, in the same time the prereleased bullet is still visible somewhere in the ground(unattached to the parent) where it was lying after hitting the targer....

So in brief, all I want is the duplication of an object but with the same properties as it was in the beginning.

You can also mention if there is a way that the first bullet after hitting the target or after a delay of a specific time like 20 seconds come again to the point of the gun and establishes its relation with its parent again(because after having so many duplicates the game starts to lag), Either way it is suitable please help me solve the problem because currently what I am doing is, I have made a lot of duplicates already in the hierarchy and I get them checked one by one after a several time so it's limited and very lengthy and inappropriate.

Please let me know if there is any solution...

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by logicandchaos · Apr 25, 2020 at 01:23 PM

Make a prefab of the object you want to copy, then use instantiate.. but from the rest of your post that is not what you want, you want object pooling, so all your bullets will already be created when your game starts in a list, this is the pool. You have them all not active, when you want to shoot instead of creating a new bullet you take one from the pool and then remove it from the pool, activate it, set it's transform.position to the gun barrel and when it hits something you deactivate it again and add it to the pool. This can be achieved easily in unity using OnEnable and OnDisable. class BulletPool:MonoBehaviour { public List bulletPool; }

 class Bullet:MonoBehaviour
 {
     void OnEnable()
     {
         if(BulletPool.bulletPool.Contains(this))
            BulletPool.bulletPool.Remove(this);
     }
     void OnDisable()
     {
         if(!BulletPool.bulletPool.Contains(this))
            BulletPool.bulletPool.Add(this);
     }
 }

That should get you started look into object pooling.

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

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

whats wrong with my enemy respawn script???? 1 Answer

Teleport (Respawn) is Not Working in a 3D Project. 2 Answers

How do I make my player re-spawn in its original place on collision of enemy? 1 Answer

(Solved!) OnEnable spams error messages 1 Answer

Respawn System not Moving Character 0 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