Download

Creating splines at runtime?

I want to create SplineComponents at runtime to create interpolated movement paths for the player pawn (like vaulting up over an obstacle).

However whenever I create a test spline component and add two points, it always says it 0 in length:



simulated function SplineComponent GetVaultPath()
{
    local SplineComponent spline;
    local InterpCurvePointVector point;

    spline = new class'SplineComponent';

    point.OutVal = Location + vect(100, 0, 100);
    spline.SplineInfo.Points.AddItem(point);

    point.OutVal = Location + vect(-100, 0, 300);
    spline.SplineInfo.Points.AddItem(point);

    `log(">>>>>>>>>"@spline.GetLocationAtDistanceAlongSpline(0));
    `log(">>>>>>>>>"@spline.GetLocationAtDistanceAlongSpline(50));
    `log(">>>>>>>>>"@spline.GetLocationAtDistanceAlongSpline(100));

    return spline;
}

This code always returns the first point location when i call GetLocationAtDistanceAlongSpline(someDistance), and if I call GetSplineLength() it always returns zero.

Any ideas what I’m doing wrong?

What I saw about splines mentioned actors, so I’m guessing you either need to spawn the splinecomponent like an actor rather than just create it with “new”, or spawn a spline actor with a spline component inside of it.

@ciox Thanks for the response. Yes, you’re right. It seems if you spawn spline actors and connect them, then the spline components connecting them will correctly return length, loc-at-dist-along-spline, etc. The main annoying thing about this is that you have to handle computing over multiple spline components rather than a single one. Good to know there is a work-around though.

When you make a new your making a pointer. if pointers are used in script then you’ll need to use this -> as the access pointer and not the dot. as its a memory address not a value. see if that works.

you can bring it out of a memory location by using



SplineComponent OurSpline = *spline;


i have not tried this in script to see if these pointers actually work in script.

@gamepainters Aren’t you referring to C++? I’m not aware of this type of syntax being used in Unrealscript. I could be wrong though…

yes i am, that is why i said not sure if it used in this scripting