• 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 Firestar9114 · Feb 20, 2019 at 05:19 AM · c#editor-scriptingprefabutility

How exactly are prefabs tagged with PrefabAssetType enums?

So... I have looked this up, but information seems scarce. The enum values and descriptions here: https://docs.unity3d.com/ScriptReference/PrefabAssetType.html are quite confusing. My goal is basically to determine whether an object is a prefab in the project windows that lives in my assets, or an instance that exists in the scene. I was trying to do this with gameObject.scene.name==null, but that seems to have changed since nested prefabs were introduced and it is very hacky anyway. So in Reset() and OnValidate(), I am calling PrefabUtility.GetPrefabAssetType(this.gameObject) and setting a bool which can be checked at runtime. Or I am trying to. I do not understand the output I am getting from the function at all. It looks like when I have a prefab in my project folder it returns PrefabAssetType.NotAPrefab, but when it checks the prefab instance in the scene, it returns PrefabAssetType.Regular? To me, this seems like very weird behavior? And I don't understand what PrefabAssetType.Variant would be at all... Can someone please clearly explain to me exactly what the types are and how prefabs are tagged? I'm very confused if this is even the intended behavior or if I've somehow broken something as it just seems to be very counter intuitive labeling, or I am missing something about how prefabs are categorized(and it is probably the later)

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 RobAnthem · Feb 20, 2019 at 05:25 AM 0
Share

Are you usie Selection.activeGameObject to call to the selected object in the Project folder?

avatar image Firestar9114 RobAnthem · Feb 20, 2019 at 05:40 AM 0
Share

No, is that function related to PrefabAssetType ? I am grabbing all Item components with a script from this post: https://answers.unity.com/questions/486545/getting-all-assets-of-the-specified-type.html and I just want to be sure that it is always grabbing a prefab(Which I think will always be true?). Then I grab all the item components later using Item[] instances = (Item[])Resources.FindObjectsOfTypeAll(typeof(Item)); and I want to be sure that I am only acting on the item components in all my scenes, not the prefabbed ones in my project folder. This is important because all my item prefabs need a unique GUID and after a GUID is added/changed I update all the instances to ensure everything stays in sync. I can then use the GUID to get the prefab at run-time and instantiate more as needed, and because I am using an int for my ItemGUID it can serialize it and use it to save/load my game's items to JSON. GUIDs are unique to the prefab in my architecture though, not necessarily the item script subclass. Thus I am trying to generate and track these GUIDs in editor scripting and I need to differentiate between components in prefabs and components actually on GameObjects in the scene.

Edit: I also need to do a check in the Item's Reset() and OnValidate() callbacks.

avatar image RobAnthem Firestar9114 · Feb 20, 2019 at 06:47 AM 0
Share

Pretty sure you have to load the resource before Resources.FindObjectsOfTypeAll does anything with your assets. You can use something like Resources.LoadAll("/Items", typeof(Item)); and then your FindAllOfType might actually do something that doesn't return scene assets. If you want to get ONLY assets from the project resources folder, use the returned list from Resources.LoadAll

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

99 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 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 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 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Renderer on object disabled after level reload 1 Answer

Drag States in Custom Editor Window 1 Answer

How to access Custom Inspector own gameObject 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges