Announcement

Collapse
No announcement yet.

TFunctionRef becomes nullptr after timeline finished inside a lambda. Is this behaviour intended?

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

    TFunctionRef becomes nullptr after timeline finished inside a lambda. Is this behaviour intended?

    [TL/DR] TFunctionRef parameter becomes null inside a lambda called after a timeline finish


    I have two actors. Player and Cannon. When the player fires the cannon he must wait until the timeline of the cannon is finish before he can move again. So i created a functions with a callback to notify the player.

    Inside LoadAmmo OnLoadCompletedCallback is not null (checked with breakpoints) but when it is called after the timeline is over, it has null value.

    Now, i changed TFunctionRef<void()> for a Delegate (using DECLARE_DELEGATE) and it works ok . References is not becoming null.

    So i fixed but i would like to know why this happens.


    [Bonus question] it is possible to bind a lambda to FOnTimelineFloat ( AddInterpFloat callback)?


    Code:
    void APlayerCharacter::LoadCannon(ACannon* Cannon)
    {
        if(carriedAmmo.Num()==0)return;
        if(currentAction!=EPlayerActions::MOVE)return;
        currentAction = EPlayerActions::LOADING_CANNON;
         Cannon->LoadAmmo(carriedAmmo, [&]()
         {
             carriedAmmo.Empty();
    
             currentAction = EPlayerActions::MOVE;
    
         });
    
    
    }
    Code:
    void ACannon::LoadAmmo(TArray<AAmmunition*> AmmoStack, TFunctionRef<void()> OnLoadCompletedCallback)
    {
        if (loadCurve == nullptr)return;
    
        FOnTimelineFloat timelineProgress;
        FOnTimelineEventStatic onTimeLineFinished;
        ///OnLoadCompletedCallback is NOT NULL HERE
        ///AmmoStack is NOT NULL here
        timelineProgress.BindUFunction(this, FName("TimelineEvaluateFloat"));
        onTimeLineFinished.BindLambda([&, AmmoStack, OnLoadCompletedCallback]()
        {
            OnLoadCompletedCallback();///OnLoadCompletedCallback es null here?why
            for (AAmmunition* ammo : AmmoStack)///AmmoStack is Not NULL here ?why
            {
                ammo->Destroy();
    
            }
        });
    
        loadTimeLine->AddInterpFloat(loadCurve, timelineProgress);
        loadTimeLine->SetTimelineFinishedFunc(onTimeLineFinished);
        loadTimeLine->SetPlayRate(4);
        loadTimeLine->PlayFromStart();
    }
Working...
X