Announcement

Collapse
No announcement yet.

4.8 ULandscapeSplinesComponent ControlPoints and Segments now protected. How to get around??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    4.8 ULandscapeSplinesComponent ControlPoints and Segments now protected. How to get around??

    I have been looking at the Rollercoaster plugin code that TeddyO(not me) orginally wrote for 4.7 and earlier. In it, he had to "nasty hack" (as he puts it) his code to gain access to the protected variables of Landscape Spline Info. I thought fine! As long as it works, everyone is happy. It compiles alright in 4.6 and 4.7 so I thought that I would recompile his code for 4.8. Guess what, it failed. It seems that two more variables have been included in the protected shield, namely:

    Code:
    Error 3 error C2248: 'ULandscapeSplinesComponent::ControlPoints' : cannot access protected member declared in class 
    
    'ULandscapeSplinesComponent' C:\Users\TedGame\Documents\Unreal Projects\RollerBuild4_8\Plugins\RollercoasterPlugin\Source
    
    \RollercoasterPlugin\Private\RollercoasterPlayerController.cpp 114 1 RollerBuild4_8
    
    Error 4 error C2248: 'ULandscapeSplinesComponent::Segments' : cannot access protected member declared in class 
    
    'ULandscapeSplinesComponent' C:\Users\TedGame\Documents\Unreal Projects\RollerBuild4_8\Plugins\RollercoasterPlugin\Source
    
    \RollercoasterPlugin\Private\RollercoasterPlayerController.cpp 120 1 RollerBuild4_8


    Here are snippets of the code where the variables are used:

    Code:
    	if (GetPawn())
    	{
    		for (TObjectIterator<ULandscapeSplinesComponent> ObjIt; ObjIt; ++ObjIt)
    		{
    			TrackSplines = *ObjIt;
    
    			ULandscapeSplineControlPoint* ClosestControlPoint = nullptr;
    
    			//Find the controlpoint closest to the player start point
    			FVector PlayerStartLocation = GetPawn()->GetActorLocation() - TrackSplines->GetOwner()->GetActorLocation();
    			float ClosestDistSq = FLT_MAX;
    			for (int32 i = 0; i < TrackSplines->ControlPoints.Num(); i++)
    			{
    				float DistSq = (TrackSplines->ControlPoints[i]->Location - PlayerStartLocation).SizeSquared();
    				if (DistSq < ClosestDistSq)
    				{
    					ClosestDistSq = DistSq;
    					ClosestControlPoint = TrackSplines->ControlPoints[i];
    				}
    			}
    
    			//Build up an ordered list of track segments (the TrackSplines->Segments array can be in random order)
    			bool bTrackHasErrors = false;
    			OrderedSegments.Empty(TrackSplines->Segments.Num());
    			ULandscapeSplineControlPoint* CurrentControlPoint = ClosestControlPoint;
    So, my question is threefold:

    1) Why are these variables protected now when before 4.8 they were not?
    2) Is there another way of accessing these variables without the "nasty hack" of pointer arithmetic?
    3) I am researching on reinterpret_cast as a viable candidate if nothing else is available. Would that work?

    Please help. Thanks in advance
    Last edited by TheJamsh; 08-18-2015, 05:09 AM. Reason: Added Code Tags

    #2
    I've got the exact same issue, can't figure out why, it was properly working in previous versions ...

    A little bump wouldn't hurt !


    Fitz

    Comment


      #3
      If they have been moved, there should be an accessor function to go along with them. Try searching for something like 'GetControlPoints()' or similar for each object. Really they should have always been protected, because otherwise people can 'get' the points and accidentally modify them causing all kinds of debugging problems. Usually all of these variables should be hidden behind accessor functions (usually inlines since they're faster).

      As a last-resort, you could make your custom class a 'Friend' of the ULandscapeSplinesComponent class, which would give you full access to private and protected members. That's not really recommended though, since you could do something you shouldn't and cause yourself all kinds of problems.

      Comment

      Working...
      X