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
1
Question by Pacosmico · Jun 03, 2015 at 11:44 AM · instantiateprefabaddcomponent

(Similar Prefabs) vs (Single Prefab + AddComponent)

The thing : I have a "Ninja Enemy" concept. But there are several "kinds" of "Ninja Enemy". So right now my Unity Project has as many Prefabs as "kinds" of ninjas. The thing is, the prefabs have quite a lot similarities, but they differ in one component that is the "special ability" The problem is, when I want to tweak somthing that affects all Ninjas it's a drag.

MY solution : is going to be, create a single prefab to instantiate and AddComponent according to the kind of ninja it is.

  • > ¿What the experts say about this?

  • > My main concer ¿Any unexpected measurable performance hit about that?

  • > ¿Is there a waaaaay better method to aproach this?

Bit more Context : I'm making my game, with lots of not excellent decision, some I can update to better, others I rather left them bad. My criteria usually is "If it's taking longer to keep this system than making a new one, change". Because the project is already quite developed.

Excuse my english

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 Oribow · Jun 03, 2015 at 07:14 PM 1
Share

I remember reading that Prefabs only save how to change a normal GameObject. If you drag a Prefab in Scene, Unity basicly creates a new GameObject and apply the changes stored in the Prefab. There should be no Performence differences at all.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by neonblitzer · Jun 03, 2015 at 07:30 PM

No need to worry about performance, unless you're spawning loads of them during one frame, in which case you should create them at Start and just enable them at runtime to avoid hiccups.

The design sounds good. If the special abilities get complex, you should separate them into their own GameObjects and make them into prefabs too, and then instantiate and parent them to the ninjas. Easier to manage and modify than hard-coding AddComponent calls :)

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

Answer by PhoenixInvertigo · Jun 04, 2015 at 07:25 AM

Not an expert, but you should be able to make the Ninja class, then make several classes that inherit from it, and putting the special ability code in the children classes. Then when you need to tweak the entire Ninja class, you're able to do so without having to jump through a bunch of hoops.

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 neonblitzer · Jun 04, 2015 at 10:03 PM 0
Share

This is nice especially if you're used to inheritance-based specialization, as in many "conventional" software projects. On the other hand, Unity as an environment facilitates and encourages composition-based approach, i.e. having features as separate components and dynamically linking them together. It's usually also easier for novice programmers and game designers to learn and get started (GetComponent versus polymorphism).

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

Associate objects to a prefab 1 Answer

Problem with AddComponet(SCRIPT) on a Instantiated PREFAB 0 Answers

prefab always instantiates at 0.0.0 1 Answer

Setting the parent of a transform which resides in a prefab error 1 Answer

prefab instantiated by script containing ShadowCaster2D bugs out 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