UPrimitiveComponent - I'm having a terrible time here!

I can’t believe this is happening. First I had trouble last night because I inadvertently put a semicolon where it didn’t belong, so today I thought it was fixed but I’m still having horrible issues and can’t for the life of me see what I’m doing wrong:

// Find all the overlapping actors
TArray<AActor*> OverlappingActors;
PressurePlate->GetOverlappingActors(OUT OverlappingActors);

// Iterate through them adding their masses
for (const auto* Actor : OverlappingActors)
	TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass;
	UE_LOG(LogTemp, Warning, TEXT("%s on pressure plate"), *Actor->GetName())

return TotalMass;


This has returned these 2 errors:

Error C3867 ‘UPrimitiveComponent::GetMass’: non-standard syntax; use ‘&’ to create a pointer to member

Error C2297 ‘+=’: illegal, right operand has type ‘float (__cdecl UPrimitiveComponent::* )(void) const’

I’m sure it has something to do with the fact that I’m using Visual Studio 2019 and Unreal Editor 4.22.3 while Ben is using the older versions in this video (Iterating over TArray with for) but I’m just completely lost at this point. Everything has been going perfectly fine until now. Does anybody have any idea what I can do about this? I can’t get a successful build in VS and my compile fails in UE. Thanks in advance for any help

First of all, you are calling a method with GetMass(), so if my clue literally a few words back has not given you a hint… you need to include some parentheses (or brackets or whatever people use; I myself get confused with the nomenclature but where I come from the term is parenthesis). Basically you are missing the ‘()’ there. I was at that part of the lecture a long time ago so I don’t quire remember, but be sure to include any parameters if required. If none are, then GetMass() is what you want.

Also, I could be wrong but maybe you don’t need the const in the for loop definition, I usually don’t use it, but if the above fixes all your problems then I guess you can keep it there.

THANK YOU a million times over!!! You are a savior and I truly appreciate your help because that absolutely worked!!!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms