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 Ckboyd89 · Jan 22, 2013 at 02:48 AM · performanceaddcomponent

Will using AddComponent frequently lower performance?

I'm creating a Scrolling Shooter/Shmup RPG that will be using a lot of unique enemies. I currently have an Event Director scripted that controls the spawning of enemies and objects. To speed things up in the long run, I was thinking about scripting a system that will use AddComponent to create unique enemies at run-time. I'd be adding various Movement and Combat scripts to a single prefab, which all enemies would derive from. In the long run, this would make creating new enemies an extremely fast process.

Now, before I decide to code the system... I'm wondering how much of an impact on performance this might make, as compared to making a ton of predefined enemies.

Example:

  1. Instantiate enemy prefab

  2. Modify common enemy values

  3. Add move script (Various curves, linear paths, and staged events)

  4. Modify values

  5. Add combat script (Various bullet patterns)

  6. Modify values

Comment
Add comment · Show 1
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 KiraSensei · Jan 22, 2013 at 10:08 AM 0
Share

I'm not really answering your question, so I post only this as a comment. You can also put all your deactivated components in your prefab, and then on runtime activate only what you want. This should be better (performances speaking).

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by whydoidoit · Jan 22, 2013 at 10:13 AM

Well to start with instantiating at run time is a bit expensive in terms of performance and yes doing your own AddComponent isn't exactly brilliant either. How about you add all of the components to a prefab, instantiate a pool of (say) 20 enemies and then configure them by enabling and disabling the components that have been added - then your runtime performance would be much better and you should get the same result.

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

12 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

Related Questions

Is there such thing as a recommended Component cap? 0 Answers

To what extent can the tree system be used instead of the details system 0 Answers

Best Practice For Shader Complexity + IOS 1 Answer

C# Invoke vs. Unity SendMessage 2 Answers

Does a coroutine do all its work during one frame? 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