• 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 apollyonbob · Mar 16, 2012 at 01:32 AM · instantiateprojectileclone

GameObject.Instantiate not using real time values?

So I'm having a problem with cloning a GameObject. I have something that emits a projectile, like a bullet. This projectile contains information that I pass on to the enemy I hit. Yes, I know what Raycasting is. Yes, this is exactly how I want to do it. I want to clone an existing projectile, then fire that clone at an enemy, then have collision detection destroy the clone.

CurrentProjectile = GameObject.Instantiate(Projectile) as GameObject; if (CurrentProjectile.GetComponent<VerboseProjectile>() != null) { CurrentProjectile.GetComponent<VerboseProjectile>().IsActive = true; } CurrentProjectile.name += System.Guid.NewGuid().GetHashCode(); WoundingProjectile wounding = CurrentProjectile.GetComponent<WoundingProjectile>(); WoundingProjectile wounding2 = Projectile.GetComponent<WoundingProjectile>();

In the above example, wounding.Wounds = List with a count of 1 and wounding2.Wounds = null.

Here's what the List declaration looks like

public List<Wound> Wounds;

It's just a public field.

So here's a wrinkle - Wounds is not set in the Editor. Wounds changes at runtime. Does GameObject.Instantiate not care about the current state of the object? Does it only keep track of state at Awake/Start?

Maaan it just dawned on me that's probably the case. But whyyyy argh.

Is there any way to force GameObject.Instantiate() to look at the current state of the object that it's cloning?

Just as an aside, I know I have specific types in there, but those are for debugging. Ideally, this component does not KNOW what kind of Projectile it's dealing with. I need it copy all the current fields of the Projectile it's cloning without having to know what all of those fields are, at runtime. Thoughts?

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

Answer by DaveA · Mar 16, 2012 at 01:47 AM

Yeah, you have to copy the current state over to the clone yourself. There's been work on doing that generically, I think it deals with Reflection. There is a Component Copier in the Asset Store I don't know if it has source, but it might be an inspiration for a runtime component copier.

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 DaveA · Mar 16, 2012 at 01:48 AM 0
Share

You should vote for this option, to copy current state when cloning, at feedback.unity3d.com

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Bullet instantiates sometimes in wrong posiiton 0 Answers

Instantiate Reference Problem 1 Answer

Cloned interactivecloth not acting like original interactivecloth. 0 Answers

Cloning Objects with Instantiate() - variables/references for added Components not stored? 3 Answers

Setting an objects instantation rotation? 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