How to use SetActive node in C++?

Hello, I want to do something like you see in the function:

void AVeahicleSounds::PlayHorn()
{
	if(bHornPressed)
	{
		if (IsValid(CollectionVehicleHorns))
		{
			if (CollectionVehicleHorns->Datas.IsNotAlreadyHorn)
			{
               Log("HornPressed True");
				VehicleHorn->SetActive(true);
				VehicleHorn->SetActive(new);
			}
		}	
	}else if(bHornReleased)
		{
            Log("HornPressed False");
			VehicleHorn->SetActive(Reset);
		}
	return;
}

The problem is the horn never activated when the key is pressed.
But the string is logged on the screen to show horn pressed.

hi Alexa, I think you don’t need SetActive new just do it setting it to true.

give it a try, cheers !

1 Like

Thank you sir for reply, but still the horn is not activated, but doing this using blueprint is fine.

void AVeahicleSounds::PlayHorn()
{
	UE_LOG(LogTemp, Warning, TEXT("PlayHorn"));

	if(bHornPressed)
	{
		UE_LOG(LogTemp, Warning, TEXT("bHornPressed"));

		if (IsValid(CollectionVehicleHorns))
		{
			if (CollectionVehicleHorns->Datas.IsNotAlreadyHorn)
			{
				UE_LOG(LogTemp, Warning, TEXT("HornPressed True"));
				
				VehicleHorn->SetActive(true);
				// VehicleHorn->SetActive(new); WRONG PARAMETER TYPE
			}
		}	
	}
	else if(bHornReleased)
	{
		UE_LOG(LogTemp, Warning, TEXT("HornPressed False"));
				
		VehicleHorn->SetActive(/*true OR false*/, true);
		// VehicleHorn->SetActive(Reset); FIRST PARAMETER IS NOT RESET
	}

	//return; NO NEED
}

SetActive function:

virtual void SetActive(bool bNewActive, bool bReset) 

https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Components/UActorComponent/SetActive/

To Reset you need to use first a boolean to bNewActive ( true or false ), then true to Reset.

1 Like

Thank you sir for explaining in more details, now this answer works for me )

1 Like