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 vexe · Dec 03, 2014 at 10:32 AM · prefabassetscriptableobject

Why is it that I can make prefabs (which are assets) reference scene objects but not be able to do the same for ScriptableObjects?

According to Bunny here, ScriptableObjects are assets, assets can only reference other assets and not scene objects. Scene objects can reference other scene objects and assets alike. Question is, aren't prefabs considered to be assets as well? If so, why is it that I can reference scene objects from prefabs? i.e.

 public class TestSO : ScriptableObject
 {
    public Object obj; 
 }
 
 public class TestBeh : MonoBehaviour
 {
    public Object obj;
 }

Creating an asset of TestSO and trying to drag-drop a scene object to 'obj', Unity won't allow me. Creating a prefab of TestBeh and doing the same, I can assign 'obj'! Why?

Can someone elaborate on this a bit?

Thanks.

Edit: It was a mistake as I was 'user the impression' that I was using a MonoBehaviour when I was able to assign scene objects to prefabs, but I was not, I was using a custom BetterBehaviour. You definitely can't and shouldn't assign scene objects to prefabs. End of story.

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

Answer by troien · Dec 03, 2014 at 11:15 AM

Well, you can't, and you shouldn't be able to. (When I try to do that, I can't at least).

But maybe you misunderstood something.

Because 'Scene Objects' are objects that are used in the scene and are shown in the hierarchy of a scene. Assets are things that reside inside the asset folder, in Unity they are visible inside the Project window. Any prefab in the project window can't reference scene objects (from the hierarchy) but can reference other assets (From the project window).

The reason for this is simple, There can be more then one scene. If you would have a reference to a object in the scene, and then try to instantiate the prefab in another scene, the reference would be broken as the thing that you are referencing doesn't exist inside the other scene. But assets can still reference other assets

What you can do however is instantiate a prefab (when you drag a prefab from the project folder to the hierarchy) and then drag a scene object into one of the fields of the instantiated prefab. Because Instantiated prefabs are scene objects, with a link to an asset. They are not assets themselves, only the prefab in the Project window is an asset.

Comment
Add comment · Show 5 · 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 vexe · Dec 03, 2014 at 11:25 AM 0
Share

Thanks. This makes sense, but this is why I asked the question. I 'can' drag scene references to prefabs, unity won't disallow me. Going into a different scene however and checking the prefab's values that it got from the other scene, they're now null (makes sense). Unless we're missing something, this could be a bug where someone forgot to put in false in ObjectFields' 'allowSceneObjects' flag

avatar image troien · Dec 03, 2014 at 11:30 AM 1
Share

Are you using a custom inspector of some sort. Which uses an ObjectField with allowSceneObjects set to true?

Otherwise I indeed think this might be a bug ye... When I try your setup I'm not able to assign any scene objcet to that field if it is a prefab.

avatar image vexe · Dec 03, 2014 at 11:34 AM 0
Share

Yes Lol my bad. I forgot that I was using BetterBehaviour (from VFW) ins$$anonymous$$d of $$anonymous$$onoBehaviour.

avatar image troien · Dec 03, 2014 at 11:41 AM 1
Share

Ok,

For people looking how to fix this. If you have access to the Editor script, you might want to set the allowSceneObjects of any/all the ObjectField's to '!EditorUtility.IsPersistent(target)' as seen in this example. That way you can't add Scene Objects to it when it is an asset. But can when it is a Scene Object.

avatar image vexe · Dec 03, 2014 at 12:23 PM 0
Share

Or use !AssetDatabase.Contains(target) - Not sure if there's a difference, is there?

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

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

Related Questions

Saving changes to the asset files for Prefab and Scriptable objects. 1 Answer

Add a GameObject as a sub-asset of a ScriptableObject 1 Answer

ScriptableObject assets null on startup, then reappear? 1 Answer

Getting a prefab with javascript FindAsset (Solved) 0 Answers

Creating prefab from instance of a GameObject loses materials 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