The comment describing UClass::HasProperty() indicates that it checks to see if a specified property exists in a class, or a parent of that class. However, when a property that exists in a child of that class is passed in, HasProperty() still returns true.

Steps to Reproduce
  1. Create a new Basic Code project.
  2. Add a new Actor code class to the project.
  3. Add the following property to the header file for the new Actor:
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = TestCat)
    USceneComponent* MyComp;
  4. Add the following code to the new Actor's constructor:
    	MyComp = CreateDefaultSubobject<USceneComponent>(TEXT("MyComp"));
    	UProperty* prop = this->StaticClass()->FindPropertyByName("MyComp");
    	if (prop)
    		bool bResult = AActor::StaticClass()->HasProperty(prop);
    		if (GEngine)
    			if (bResult)
    				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::MakeRandomColor(), TEXT("AActor has MyComp."));
    				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::MakeRandomColor(), TEXT("AActor does not have MyComp."));
  5. Build the project in Visual Studio.
  6. Open the project in the Editor.
  7. Place an instance of the new Actor class into the level.
  8. Start PIE.

A message is displayed on the screen indicating that AActor contains MyComp.

A message is displayed on the screen indicating that AActor does not contain MyComp.

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-67859 in the post.

Login to Vote

ComponentUE - Foundation - Core
Affects Versions4.
Target Fix4.22
Fix Commit4687831
Main Commit4772220
Release Commit4862694
CreatedDec 21, 2018
ResolvedJan 8, 2019
UpdatedFeb 12, 2019
View Jira Issue