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 sun_spider · Feb 27, 2014 at 11:20 AM · editorprefabcomponentreferencetype

Reference to Scene Object Component in Prefab Editor, 'Type Mismatch'?

I have a reference to a component on an object in my scene, stored in a component in my prefab. Declared like this:

  public Component component;

I have a custom editor that uses this line to display it:

 EditorGUI.PropertyField( tempPosition, property.FindPropertyRelative("component"));

The Inspector shows "Type Mismatch" where the component should be.

What's strange is my reference works fine when I apply a component from the same object, or from a component on an object in the scene. Also, when I instantiate the prefab, the instance shows the reference as expected, that is: 'object (component)'.

So really everything is working fine except my custom editor looks a little stupid when it says 'Type Mismatch' on my prefab. Anyone have any clues what this might be?

Comment
Add comment · Show 5
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 vexe · Feb 27, 2014 at 11:23 AM 0
Share

what type of components do you reference?

avatar image sun_spider · Feb 27, 2014 at 11:54 AM 0
Share

$$anonymous$$onobehaviors

avatar image vexe · Feb 27, 2014 at 12:01 PM 0
Share

then why have a Component reference if you just want $$anonymous$$onoBehaviours? Try using a $$anonymous$$onoBehaviour ins$$anonymous$$d of Component. do you still get that miss-match?

avatar image sun_spider · Feb 27, 2014 at 08:47 PM 0
Share

I actually want to allow Components as well, though I'm mostly working with mono-behaviors right now.
Point is, it works perfectly in almost every way. The data is there and functioning... it's seems to be just the editor display that is not working properly... so I don't imagine there's anything very wrong with how I'm doing it... maybe just something that needs to be cast or somesuch. I can't even really test to see if it's happening because when I do a print of what's stored in the field, it reports that I have my behavior (or component) and everything looks normal. No error messages in debug or anything.

avatar image sun_spider · Feb 28, 2014 at 07:07 AM 0
Share

Actually, turns out everything only works perfectly until you reload the scene. Then the problem settings don't work. Are prefabs not allowed to hold references to instantiated objects, maybe?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sun_spider · Mar 01, 2014 at 09:34 PM

I found some info on this. It has to do with prefabs not being able to contain references to GameObjects in the scene. I don't see why Unity couldn't make this work, but I created a workaround involving using inactive GameObjects instead of prefabs, and instantiating them instead. Works fine, but would be nice if prefabs didn't have this constraint.

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 robertbu · Mar 01, 2014 at 09:37 PM 1
Share

It doesn't work because 1) prefabs are just designs/blueprints for an object, not a 'real' object, and 2) they can be reused in multiple scenes. You can link internally. The typical workaround is to have the prefab find and initialize links in Start() using things like GameObject.Find() or GameObject.FindWithTag().

avatar image sun_spider · Mar 01, 2014 at 10:10 PM 0
Share

I get that and it makes sense. In thinking about it I guess there should just be a more obvious warning when you try to do this.

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

21 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

Related Questions

Editor: Is it possible to move a component of a Prefab Gameobject Child to it's parent?? 1 Answer

Inspector:Reference a component in Assets, not in scene. 0 Answers

How to keep reference linked when replace prefab through editor scripts? 1 Answer

Instantiating scripts with references to prefabs loses the reference. 1 Answer

Targeting parts of a Prefab more than 1 level down? 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