diff --git a/LibCarla/source/carla/client/Actor.cpp b/LibCarla/source/carla/client/Actor.cpp index 3932aabb8..36cb0bc41 100644 --- a/LibCarla/source/carla/client/Actor.cpp +++ b/LibCarla/source/carla/client/Actor.cpp @@ -88,6 +88,10 @@ namespace client { GetEpisode().Lock()->SetActorCollisions(*this, enabled); } + void Actor::SetActorDead() { + GetEpisode().Lock()->SetActorDead(*this); + } + void Actor::SetEnableGravity(const bool enabled) { GetEpisode().Lock()->SetActorEnableGravity(*this, enabled); } diff --git a/LibCarla/source/carla/client/Actor.h b/LibCarla/source/carla/client/Actor.h index e86bf3f28..639a7ecb2 100644 --- a/LibCarla/source/carla/client/Actor.h +++ b/LibCarla/source/carla/client/Actor.h @@ -102,6 +102,9 @@ namespace client { /// Enable or disable collisions on this actor. void SetCollisions(bool enabled = true); + /// Set actor as dead and starts his life span + void SetActorDead(); + /// Enable or disable gravity on this actor. void SetEnableGravity(bool enabled = true); diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index 0733b1f7d..04b21f26d 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -416,6 +416,10 @@ namespace detail { _pimpl->CallAndWait("set_actor_collisions", actor, enabled); } + void Client::SetActorDead(rpc::ActorId actor) { + _pimpl->AsyncCall("set_actor_dead", actor); + } + void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) { _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled); } diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 8f44b962f..3d5ee9b8e 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -240,6 +240,9 @@ namespace detail { rpc::ActorId actor, bool enabled); + void SetActorDead( + rpc::ActorId actor); + void SetActorEnableGravity( rpc::ActorId actor, bool enabled); diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index bd600740f..69b3c04d4 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -435,6 +435,10 @@ namespace detail { _client.SetActorCollisions(actor.GetId(), enabled); } + void SetActorDead(Actor &actor) { + _client.SetActorDead(actor.GetId()); + } + void SetActorEnableGravity(Actor &actor, bool enabled) { _client.SetActorEnableGravity(actor.GetId(), enabled); } diff --git a/LibCarla/source/carla/client/detail/WalkerNavigation.cpp b/LibCarla/source/carla/client/detail/WalkerNavigation.cpp index dbce47232..87f934e98 100644 --- a/LibCarla/source/carla/client/detail/WalkerNavigation.cpp +++ b/LibCarla/source/carla/client/detail/WalkerNavigation.cpp @@ -66,6 +66,7 @@ namespace detail { if (_nav.IsWalkerAlive(handle.walker, alive)) { if (!alive) { _client.SetActorCollisions(handle.walker, true); + _client.SetActorDead(handle.walker); // remove from the crowd _nav.RemoveAgent(handle.walker); // destroy the controller diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp index cfea3ea83..f9dacdc91 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp @@ -1454,3 +1454,26 @@ ECarlaServerResponse FWalkerActor::GetPoseFromAnimation() } return ECarlaServerResponse::Success; } + +ECarlaServerResponse FWalkerActor::SetActorDead() +{ + if (IsDormant()) + { + } + else + { + auto Pawn = Cast(GetActor()); + if (Pawn == nullptr) + { + return ECarlaServerResponse::NotAWalker; + } + auto Walker = Cast(Pawn); + if (Walker == nullptr) + { + return ECarlaServerResponse::NotAWalker; + } + Walker->StartDeathLifeSpan(); + UE_LOG(LogCarla, Warning, TEXT("Walker starting life span by dead")); + } + return ECarlaServerResponse::Success; +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h index 0f3903a05..8429eb2f8 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h @@ -415,6 +415,11 @@ public: return ECarlaServerResponse::ActorTypeMismatch; } + virtual ECarlaServerResponse SetActorDead() + { + return ECarlaServerResponse::ActorTypeMismatch; + } + virtual ECarlaServerResponse FreezeTrafficLight(bool) { return ECarlaServerResponse::ActorTypeMismatch; @@ -609,6 +614,8 @@ public: virtual ECarlaServerResponse BlendPose(float Blend); virtual ECarlaServerResponse GetPoseFromAnimation(); + + virtual ECarlaServerResponse SetActorDead(); }; class FOtherActor : public FCarlaActor diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.h index 4694c3335..5558e5b4e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEpisode.h @@ -352,6 +352,8 @@ private: bool SetActorCollisions(FCarlaActor &CarlaActor, bool bEnabled); + bool SetActorDead(FCarlaActor &CarlaActor); + void TickTimers(float DeltaSeconds) { ElapsedGameTime += DeltaSeconds; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index 42ad45835..ca3e6b713 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -1409,6 +1409,30 @@ void FCarlaServer::FPimpl::BindActions() return R::Success(); }; + BIND_SYNC(set_actor_dead) << [this]( + cr::ActorId ActorId) -> R + { + REQUIRE_CARLA_EPISODE(); + FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId); + if (!CarlaActor) + { + return RespondError( + "set_actor_dead", + ECarlaServerResponse::ActorNotFound, + " Actor Id: " + FString::FromInt(ActorId)); + } + ECarlaServerResponse Response = + CarlaActor->SetActorDead(); + if (Response != ECarlaServerResponse::Success) + { + return RespondError( + "set_actor_dead", + Response, + " Actor Id: " + FString::FromInt(ActorId)); + } + return R::Success(); + }; + BIND_SYNC(set_actor_enable_gravity) << [this]( cr::ActorId ActorId, bool bEnabled) -> R diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h index d032d5d57..676569ed4 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h @@ -21,4 +21,12 @@ public: UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere) bool bAlive = true; + UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere) + float AfterLifeSpan = 10.0f; + + UFUNCTION(BlueprintCallable) + void StartDeathLifeSpan() + { + SetLifeSpan(AfterLifeSpan); + } };