Listview Items reference

Hello, I’m having a hard time understand how the Listview Items are stored and how to get their reference.

I have the following BP:

That creates an item and adds it to an ItemList. Works pretty well. Then I have:

This, from what I understood, passes a reference of the actual item being draw to… somewhere. Some instance of the item I have no idea where, but it works until here. If I do this:

It gets the correct reference and works fine, but beyong that there is no way for me to get a reference to any item. For example, if I try this:

It should also work, but I get an error saying “Accessed none trying to read property ItemName”.

So the OnItemIsHovered, or any other event, actually passes a reference to some object, but I have no idea what that object is. Even if I do this:

What I think it should happen is: I get a reference to the item that I saved and actually worked before and try to modify it, but nothing happens. The print doesn’t even fire, not even an error.

So I just realized I have no idea where the items are actually stored and where I can go to change their properties, or if I even can do it. I can work around my problem if I put some item in the widget and work around the problem, but I think I need to understand exactly how this list works.

Thanks for your help, fellas.

It seems to me that you need to use an array here. If not, you are getting the ref to the last added widget only.
Here is a quick guide : Blueprint Arrays | Unreal Engine Documentation

So, even if I get the items from the array that’s supposed to hold all the items, they are all nulled on their properties. For example:

Still has an “Accessed none trying to read property” on every item, so I don’t know where even the right items are to store them.

Are item widgets successfully added to the list view? I mean do you see them ingame?

Yes, I see them and if I use the Event OnListItemObjectSet I can actually change their properties, but after that everything is lost into a limbo of objects.

You don’t add those widgets to a dedicated array but they should be accessible with the “get list items” you are using.
What if you print the length of this array? Does it give you the correct number?

image

These are the 5 items in the List. In my head they should be 100% working, makes no sense. If I print the name of the items on the event that actually passes a valid reference, they have the same name.

So on a certain event they are valid and on another one they are not…makes no sense to me either :sweat_smile:

Yeah, I will try to update to 4.27. I doubt it will do any good, but you never know.

Thanks for trying with me.

Maybe that could worth it to use a dedicated array. When you create the item widget and add it to the list view, add it to a ItemWidget array as well, and use this array instead

If I read the screenshots correctly you are adding ItemWidgets which are Widget Blueprints themselves. I don’t think that’s what you should normally be doing, the whole point of the ListView widget is that it only creates as many widgets of the configured Widget Class as necessary. Creating a widget for each item in the list anyway kind of works against that. Typical uses of ListView have two classes (plus the widget that contains the ListView). One containing the actual item data. And the other one that implements the UI for a single element and implements the UserObjectListEntry interface. The OnListItemObjectSet function holds a reference to an instance of the actual item data in its ListItemObject parameter.

So basically what may be happening is that you create Widgets that represent the item data and then the ListView creates additional Widgets that it actually uses to display those items.

God in heaven, thanks for the advice! I hacked my brain for 12 hours trying to understand all this, but I finally got it after seeing how the list is actually implemented in c++. They get an actual object that is not specified beforehand (I think any UObject may fit) and makes a widget for it. I could actually navigate the nodes after knowing that and what the references are for. Thank you again, brother!

What’s happening is that list view items are not always there.
They are dynamically added and removed. When in view, it will be added and the widget properties will be able to work.
Even if you had all of the widgets showing, you cannot access them as regular objects but as objects displayed by the listview container.

So let’s say you have 200 items.
If you show 5, only those 5 are represented and have available properties.
When you scroll, whatever is off screen is removed and a new item is added to the displayed list.
I wish there was an easier way to interact with this but the true way to do so is to use a list view manager that keeps track of every item that is added/removed and once you add/remove them, you use that same manager to manage the properties; essentially making the listview just a visual cosmetic that accompanies the manager.