Hi everyone, I am a new UE4-user, and using Carla to create data. Carla hat Server- and Client-Side. Its Server-Side is based on UE4. In another word, it is a UE4 project. The two sides connect each other with TCP. Now I need to toggle objects selectively. But Carla API only provides the ToggleVisibilty of environment objects. I also need to toggle actors (walkers and vehicles) off. I have purchased the Plugin UDP Socket Server in Marketplace and used it to connect the UE4 and Carla-Client and toggle the actors (walkers and vehicles) off. So I send the message (e.g. : “vehicle.coordinate_X, coordinate_Y”) from Carla-Client to UE4, find out the targetted actor with it, and toggle it off. Following are my event graph for the level blueprint and Cpp code. Now I have a problem, when I send many times messages to UE4, it alway causes a fetal error, e.g. Crashing. I have been thinking about this problem for about one week and now guess, the reason may be related to the togglevisibility. Possible I have toggled actors off too fast or too much. I am not sure. Can someone help me?
…
//This function is to toggle the visibility of a targetted actor using a given message.
void UMyBlueprintFunctionLibrary::ToggleVehicleOffWithGivenMessage(TArray<AActor*> Vehicles, FString message)
{
FVector location = UMyBlueprintFunctionLibrary::MessageToLocation(message); // pull out location info out of the message.
if (location != FVector(0.0, 0.0, 0.0) && (Vehicles.Num() != 0))
{
for (auto& Vehicle : Vehicles)
{
auto actor_location = Vehicle->GetActorLocation();
if (actor_location == location) //find out the actor with the location
{
Vehicle->GetRootComponent()->ToggleVisibility(); //toggle it off
}
}
}
}
// This function is used to convert a message to location info. The message is e.g. "Vehicle.100,100". Using comma and point I pull out the x and y coordinates.
FVector UMyBlueprintFunctionLibrary::MessageToLocation(FString message)
{
FString str_x = TEXT("");
FString str_y = TEXT("");
if (message.Contains(TEXT(",")) && message.Contains(TEXT(".")))
{
int32 point_index = message.Find(TEXT("."));
int32 comma_index = message.Find(TEXT(","));
for (int32 i = point_index+1; i < comma_index; ++i)
{
str_x += message[i];
}
for (int32 j = comma_index + 1; j < message.Len(); ++j)
{
str_y += message[j];
}
float x = FCString::Atof(*str_x);
float y = FCString::Atof(*str_y);
return FVector(x, y, 0.0);
}
else
{
return FVector(0.0, 0.0, 0.0);
}
}