I am shortening the C++ logic correctly?

I converted the code to short form and it compiles fine, but in the game not effecting anything.
any help appreciated thank you.

Original Logic: Working Logic

	if (::IsValid(ChildMesh))
	{
		if (IsValid(ChildMesh->SkeletalMesh))
		{
			//Logic
		}
	}

converted to short form: Not working logic

if(::IsValid(ChildMesh) ? (ChildMesh->SkeletalMesh));
	{
		//Logic
	}
1 Like

Hi @Alexa.Ki!

Can I ask why you are opting to use the Conditional ternary operator ( ? ) ? While it would compile, it has a different function than you may have intended if it is supposed to read exactly like the above code.

Whereas if you used the logical operator && and treated the second variable as a bool like

if( : : IsValid(ChildMesh) && (IsValid(ChildMesh->SkeletalMesh))

would that not be appropriate for what you are attempting to do?

Any more relevant information to what you are trying to achieve would definitely help solve your mystery and I hope this helps!

2 Likes

Funny that you can compile this :sweat_smile:

I would go with

if (IsValid(ChildMesh) && IsValid(ChildMesh->SkeletalMesh))
{
    //Logic.
}
3 Likes

I am trying to achieve this, with simple if( : : IsValid(ChildMesh) && (IsValid(ChildMesh->SkeletalMesh)) I can do it and its working, but I want to go advance and learn operator ( ? )

USkeletalMesh*  SkeletalMeshLocal = ((USkeletalMesh*)nullptr);
bool bSkeletalMeshValid = UKismetSystemLibrary::IsValid(((::IsValid(ChildMesh)) ? (ChildMesh->SkeletalMesh) : (SkeletalMeshLocal )));
	if (bSkeletalMeshValid)
	{
		//logic
	}

You mean the Ternary operator?
Then the code would look like this

IsValid(ChildMesh) ? (IsValid(ChildMesh->SkeletalMesh) ? "Skeletal Mesh Not Null" : "Skeletal Mesh Null") : "ChildMesh Null";
4 Likes

Awesome, Thank You for helping me in My Study Progress )

1 Like