# ToggleVisibility of Actors causes UE4 Crashed (fetal errors)

**URL:** <https://forums.unrealengine.com/t/togglevisibility-of-actors-causes-ue4-crashed-fetal-errors/568163>\
**Category:** C++\
**Tags:** unreal-engine, UE4, CPP, question\
**Created:** [May 27, 2022, 7:42pm UTC](https://forums.unrealengine.com/t/togglevisibility-of-actors-causes-ue4-crashed-fetal-errors/568163 "2022-05-27T19:42:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CenturyEgg1993](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CenturyEgg1993](https://forums.unrealengine.com/u/CenturyEgg1993)\
**Post date:** [May 27, 2022, 7:42pm UTC](https://forums.unrealengine.com/t/togglevisibility-of-actors-causes-ue4-crashed-fetal-errors/568163/1 "2022-05-27T19:42:05Z")

</div>

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?

 ![Structure](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/c/3/4c3cd997d104c2b44ce73496ab839cd8a81ce1eb.png)

…

```auto
//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);
	}

}

```
