• 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 Nimja · Jul 01, 2020 at 10:15 AM · editorreflectioneditorguieditor scripting

Reflection: "Field items defined on type Inventory is not a field on the target object which is of type PartyManager"

I need to make use of dictionaries in the editor, so I made my own editable Dictionary class based on parallel lists, with it's own editor script. When I make us of this script on some string->int, string->bool, and string->string dictionaries in a component, it works fine.

However, I also have a component`PartyManager` which has a member parties , which is a List<Party>. Party objects have a member inventory, which is of type Inventory, which wraps around a EditableDictionary<InventoryItem,int> member called items, where InventoryItem is a ScriptableObject.

When I inspect the PartyManagerobject, I reciever the error "Field items defined on type Inventory is not a field on the target object which is of type PartyManager". The error points towards the function

 private void InitDict(SerializedProperty dictionary) {
         if (dict == null) {
             dict = fieldInfo.GetValue(dictionary.serializedObject.targetObject) as EditableDictionary<TK, TV>;
         }
     }

dict in this case is a member of the editor script that points to the underlying EditableDictionary object.

How can I avoid this issue, and is there an explanation as to why this occurs only when the dictionary is under several layers of objects? My understanding is that fieldInfo here points to the component and thus I need to find the holding object rather than the parent component.

Thanks in advance for any help.

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
0

Answer by lennardbeers · Nov 22, 2020 at 04:14 AM

@Nimja Hey, I have the exact same problem right now. Have you got anything new on this?

I also use a custom DictionaryDrawer class and have an EditorWindow that holds a reference to another Object that has a custom SerializableDictionary field, which uses the custom Drawer. If the EditorWindow tries to draw the Object containing the Dict, I get the same error, telling me that the Dictionary property wasn't found on my EditorWindow class. All of this Editor + Serialization stuff is blowing my head up right now...

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 lennardbeers · Nov 22, 2020 at 04:20 AM 0
Share

If I understand correctly, we have to pass fieldInfo.GetValue() an instance of the Type of the class that contains the dictionary, which in my case would be the object stored inside of my EditorWindow class, not the window itself. The problem is, $$anonymous$$y custom Dictionary should work and draw correctly from anywhere and without drawing the whole Editor for the object containing it.

avatar image Nimja · Nov 22, 2020 at 11:22 AM 0
Share

Wow, it's been a while since I last looked at this.

Basically, the solution is to make a specific editor class for Inventoryitem keyed dictionaries, overriding InitDict(); in this case:

 internal override void InitDict(SerializedProperty dictionary) {
         if (dict == null) {
             Party$$anonymous$$anager party$$anonymous$$anager = dictionary.serializedObject.targetObject as Party$$anonymous$$anager;
             Debug.Log(dictionary.propertyPath);
             int idx = int.Parse(System.Text.RegularExpressions.Regex.$$anonymous$$atch(dictionary.propertyPath, @"\d+").Value);
             Inventory holder = party$$anonymous$$anager.parties[idx].inventory;
             dict = fieldInfo.GetValue(holder) as EditableDictionary<InventoryItem, int>;
 
         }
     }

Of course, this will fail if the dictionary is a member of anything that isn't a Party$$anonymous$$anager.

Sorry that I can't be more helpful.

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

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

SceneView.onSceneGUIDelegate GUI sorting problem 1 Answer

Inspector issue about draw Button(s) on top of EditorGUI fields, and "CLICK" on it. 1 Answer

EditorGUI.PrefixLabel got truncated 0 Answers

Hint at Inspector variables that have tooltips 0 Answers

Initialising List array for use in a custom Editor 1 Answer

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