Can I get the "Index Of" node to find an object inside of a Generic List?

I defined a Class called Game State and put another class in it called Activity State.

I have two graph variables:

  • One is currentActivity, of type Activity State.
  • Another is listOfActivities, which is a List of Activity States.

I want to look inside of the listOfActivities and get the index number of the Activity State that matches currentActivity. (I know for sure that the item is in the list - just want the index number of it.)

I am getting an error:

InvalidConversionException: Cannot convert from ‘System.Collections.Generic.List`1[ActivityState]’ to ‘Unity.VisualScripting.AotList’.

From what I understand, the Index Of node can not work on generic lists like Activity State. It can only work on AOT lists.

I have tried two different paths:

  1. Write a custom node that can get an Index Of for a generic list, so I can plug in my List of Activity States directly into that.
  2. Write a custom node that can convert my generic List of Activity States into an AOT list.

I have failed at both of these attempts. There is a third hacky option:

  1. I could hack a subgraph which just iterates through every item on the list and looks for a match.

I guess I could do #3, but I feel like there must be a simpler way to access the Index Of an item that I know to be on a generic list.

Does anyone have advice on how to proceed?

Use IList → IndexOf

9375476--1311191--upload_2023-9-28_19-28-39.png

1 Like

Ah wonderful! I found it in my Unity under the name List Interface:

9376433--1311347--upload_2023-9-29_10-9-25.png

Seems to be working well, thanks so much!!

1 Like