Retrieve spline components so I can access their points

I have a number of spline components in a scene. I wish to store them in an array and access their points.

I can grab them by tag or by class, e.g.

TArray streetSplines = sceneComponent->GetOwner()->GetComponentsByTag(USplineComponent::StaticClass(), FNameStreetTag);

But this returns a TArray<UActorComponent*> and not TArray<USplineComponent*> , so I cannot access the points defining the splines in the array.

How to I go about accessing the splines and storing them in TArray<USplineComponent*> so that I can iteratively access the splines and their points?

Since UsplineComponent is a derived class in inheritance hierarchy from UActorComponent

like this:

you can just use Cast<UsplineComponent>(ActorComponent) to retrieve your USplineComponent object. It’s called casting. Check: C++ Tutorial: Upcasting and Downcasting - 2020

So then while looping through you UActorComponent objects from this TArray You can just do:

	for	(auto ActorComp : ActorComponentsArray)
		auto* SplineComp = Cast<USplineComponent>(ActorComp);
		// do sth with SplineComp, but check it's validity first

Hope that helps

Splines are so annoying in Unreal Engine, I don’t know why!
They just make it overly complicated to get a spline object.
Can we have an intuitive spline struct, which has helper functions for getting the transform along a spline, getting spline points at index, ect. I know this can be done with the spline component, but not with the underlying data struct FSpineCurves. This is really annoying because sometimes you need an array of Splines or you want to store splines in a data asset. The only workaround I’ve seen is to literally dynamically create a spline component to just access these simple features, or preallocate a spline component and then feed it different spline curves, non of these are easy or intuitive.

Thank you, I hadn’t considered simply casting to the spline component.

I did just now solve the issue by populating an array with pointers to the splines to access them that way.

Thoughts on casting v. pointers? I imagine casting would be computationally more taxing than simply accessing the spline via pointer.

IMO it’s such an min/maxing that it is neglible for the most part in code. Depend’s how far You want to go with optimisation but other stuff in game will be of more struggle than this.