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 Kawaburd · Aug 17, 2013 at 11:50 PM · prefabsinheritanceoop

Prefab inheritance without scripts. Is it possible?

This is more of a hypothetical quesiton than a syntactic one. Still, if I can do this it would be convenient to say the least, and if it's in the manual, I probably missed it somewhere.

The best example I can think of is like the voxels in Minecraft. Say I have a whole bunch of prefabs with common traits - they're uniform cubes, you can walk on 'em, mine 'em, and most of them can spawn drops. But at the same time they're all different in what they can survive, what they spit out, etc.

The blocks I'm gonna be working with have most of the same basic concepts - so is there any way I can just assign them all the same solid, minable parent (pretty literally a super-prefab with sub-prefabs under it), or do I just have to copypaste some sort of class/inheritance script in every 'block' prefab type I make?

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

2 Replies

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

Answer by Slobdell · Aug 18, 2013 at 12:00 AM

I think what you're talking about IS in fact scripts, just have a script with the basic characteristics and assign to all, then have a seperate script for each different type of block that gives it it's unique traits. Or have the same script check which type of block it's assigned to and behave accordingly.

Comment
Add comment · Show 3 · 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 Brenden-Frank · Dec 02, 2013 at 01:50 AM 1
Share

The problem with this logic is that if my script has parameters on it such as hit points and speed.

I want to be able to change those on the inherited prefab too. If I don't change it, I want the defaults from the original prefab to be used and modified if the original is edited by a designer.

avatar image Loius · Jan 26, 2014 at 09:46 PM 0
Share

have you tried it? as far as i can tell you are describing exactly how unity handles inheritance. if something is working not as expected, we can probably help better.

edit: or are you saying you want subOBJECTS to be a subclass of their parent's type? that setup is going to introduce a lot of headaches, but you can automate adding in the right components with a custom editor for the base class that provides a list of options for its chilfren to be

avatar image Brenden-Frank · Jan 26, 2014 at 09:58 PM 0
Share

I know all about script inheritance. I'm talking about prefab inheritance.

One prefab would have a mesh renderer on it and some scripts. I make a child of that prefab, it also has the mesh renderer on it. If I remove the mesh renderer from the parent, the child also has it removed. I can change the mesh on the child's mesh renderer without affecting the parent.

At the very heart here I'm talking about inheritance of a gameobject's component stack.

After further investigation I believe this can be done with reflection, but its a lot of work.

avatar image
0

Answer by mahalo1984 · Jan 26, 2014 at 04:20 AM

This is a way to introduce inheritance:

http://cardboardkeep.com/dev-blog-inheritance-in-unity-3d/

Comment
Add comment · Show 2 · 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 mustafa · Aug 12, 2015 at 04:11 PM 0
Share

link is broken

avatar image Morbolworbol mustafa · Oct 24, 2016 at 04:24 PM 0
Share

http://www.cardboardkeep.com/blog/dev-blog-inheritance-in-unity-3d

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

20 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

Related Questions

An OS design issue: File types associated with their appropriate programs 1 Answer

Does Unity support multiple Inheritance? 3 Answers

Is it possible to create game object/prefab from file? 2 Answers

How to create inheritance for unity GameObjects 2 Answers

Collectible Items & Inheritance 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