How to reference components added at runtime

Hi,
I’m working on a infinite runner-like blueprint that adds static mesh components to itself at runtime along a random generated spline.
I want to delete the components that are behind the player position therefore I store all the added static mesh components to an array of structs that have a static mesh component reference and its distance along the spline:

Then every tick i check at what distance along the spline the player is and delete all the meshes that are behind:

But I always get a Accessed none trying to read propriety Static Mesh_blablabla on the “Set visbility” node.
Am i storing the components in a wrong manner? The components are there because I can read the distance and the name of the component. Can anyone tell me if I’m missing something?

Thanks!!!

Hard to tell. You delete the mesh but what happens to the struct? Perhaps you end up with a struct array entry with a dangling pointer to the deleted mesh? Does your N index account for that?

When you print it, does it all add up?

Also, here’s a quick alternative since that should be quite performant and suitable for infinite runners. It does not rely on indexing and is event driven. It may not fit with your game design / concept though. I’m gonna leave it here in case you want to experiment:

The player has an overlapping volume behind them:

And each tile fires onEndOverlap if it collides with the player.

Image from Gyazo

No casting, no Ticking, no arrays, no indexing.

Check out video #25 and #27 in the link below. They go over how to create references and the “accessed none” error.