Announcement

Collapse
No announcement yet.

UMovementComponent invalidation

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

    UMovementComponent invalidation

    Hi!
    I've created movement class and now trying to use it.

    Code:
    class CONTENT_API UMoveMotor : public UMovementComponent
    Code:
    class CONTENT_API ASteper : public AActor
    ...
    	UPROPERTY(Category = Steper, VisibleAnywhere, BlueprintReadOnly)
    	TSubobjectPtr<UMoveMotor> m_Motor;
    ...
    Code:
    ASteper::ASteper(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    {
    	m_Motor = PCIP.CreateDefaultSubobject<UMoveMotor>(this, TEXT("ShipMoveComponent"));
    
    	if (!m_Motor)
    		GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Red, TEXT("No Moving motor were constructed!"));
    
    	PrimaryActorTick.bCanEverTick = true;
    }
    ...
    void ASteper::AddNewCoursePoint(FVector position)
    {
    	if (m_Motor != NULL)
    		m_Motor->AddNewControlPoint(position);
    	else
    		GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Red, TEXT("No Moving motor"));
    }
    In ASteper constructor everything finy. But when I'm trying to call AddNewCoursePoint from parent Actor class (ASteper) it's saying that m_Motor isn't valid already.
    Ticking of movement component keep going right.

    What's the problem? Why m_Motor became invalid?
    Senior programmer from Snowforged Entertainment

    #2
    The problem was in UPROPERTY() define. Remove it for TSubobjectPtr and it will be fine.
    Senior programmer from Snowforged Entertainment

    Comment

    Working...
    X