Hi Sleicreider,

You can use PURE_VIRTUAL with non-UObjects, but there’s no reason to. I think the idea behind it was stub functions needed to exist for virtual methods so that “pure virtual” would work for BlueprintNativeEvent and other Blueprint-related virtuals.

The PURE_VIRTUAL macro just inserts a runtime assertion that says you shouldn’t ever be executing that block of code, hence why child classes don’t need to override for it to compile, because C++ doesn’t recognize it as a pure virtual method.

It appears that the traditional C++ syntax is preferred in non-UObjects and the macro is actually enforced in UObjects.

AFAIK it’s only possible to create abstract methods using PURE_VIRTUAL instead of virtual void MyMethod() = 0;
But does this PURE_VIRTUAL also work for non UObject classes? & classes without UCLASS() ?
Until now it seems that it’s also possible that child classes don’t need to implement pure virtual methods with this macro.
can anyone help?

but using c+ pire virtual functions(virtual void MyMethod() = 0); somehow doesn’t work at all in ue4 projects

PrimitiveComponent.h line 36 says otherwise.

Every UOBJECT must be isntaniciable in order for UE to create the CDO (Class Default Object) that is why UOBJECTs cannot be abstract. That just hit me hard… See How do I implement Pure Virtual Methods? - Programming & Scripting - Unreal Engine Forums

1 Like

oh ._. good to know

@thavik I don’t know what line/code you’re referring to, but that nowhere in that file could I find a pure virtual function.


He was refering to some older stages of the file from around version 4.4 where you could find /** Defines a triangle by its vertices. */ virtual void DefineTriangle(const TStaticArray<FPrimitiveTriangleVertex,3>& InVertices,const UMaterialInterface* Material) = 0; But seems like they changed some stuff in the file.

You can just check the old code on github if you linked your account.

My bad! Thanks for pointing this out. I should make better practice of checking when the answers/comments were left and taking in that context.