I get an error when declaing a URadialForceComponent

Hello.

Whenever I try to declare a URadialForceComponent variable, I get these errors: Screenshot - 2e25b652eddec76a770bc8e5ea38ce4c - Gyazo

My .h declaration looks like this:

	UPROPERTY()
	URadialForceComponent* radialForce;

And my .cpp usage:

	radialForce = ObjectInitializer.CreateDefaultSubobject<URadialForceComponent>(this, TEXT("Force"));
	radialForce->Radius = 200;
	radialForce->AttachTo(SphereComponent);
	radialForce->ImpulseStrength = 1000.0f;
	radialForce->ForceStrength = 1000.0f;

I have no idea how to fix it, do you guys have any ideas?

Looks like you aren’t #including RadialForceComponent.h .

Your error is saying that the compiler doesn’t know that “URadialForceComponent” is a type, so it is expecting that string to be an identifier rather than a type, and therefore expecting a ; after the word rather than the * .

Oh, I didn’t think I needed to. I’ll try that, thanks!

EDIT: Tried to include it, but got this error:

Cannot open include file: ‘RadialForceComponent.h’: No such file or directory

Generally you’ll need to #include the declarations for most types unless they have a declaration in a very base-level file like Object.h.

Try “PhysicsEngine/RadialForceComponent.h”

Sometimes include files are nested within a module’s folders in order to better organise the code. You’ll need to include a relative path to reference those includes.

Awesome, it compiles now! :slight_smile:

Though I can’t seem to make it work with collision responses like in blueprint.

I tried this radialForce->ObjectTypesToAffect.Add(ECC_PhysicsBody); but then I get an error saying it needs TEnumAsByte instead, any ideas? :slight_smile:

EDIT: Nevermind, I need to use radialForce->AddCollisionChannelToAffect instead.

EDIT2: Or not, seems I was wrong. Then I get another error.

You want to use URadialForceComponent::AddCollisionChannelToAffect to do it as it handles the conversion for you, from what I can tell.

By default though, the RadialForceComponent already affects Physics bodies:

// by default we affect all 'dynamic' objects that can currently be affected by forces
	AddCollisionChannelToAffect(ECC_Pawn);
	AddCollisionChannelToAffect(ECC_PhysicsBody);
	AddCollisionChannelToAffect(ECC_Vehicle);
	AddCollisionChannelToAffect(ECC_Destructible);

So you probably dont need to do that.

Oh, OK. Thanks man, you’ve been a great help. :slight_smile:

No problems. To help answerhub filter out questions that have been resolved, would you mind marking my answer as correct? Thanks.