Cannot set the root component to another component

I seem to have an understanding why there is a problem, The RootComponent is a USceneComponent type, and the CapsuleComp is a UCapsuleComponent, so trying to set one to the other doesn’t seem to work. Do I need to somehow change the root type or is it something simple I’ve missed?
If it helps, here’s the header file, but everything seems ok here.
HeaderFile

Thanks in advance!

Have you tried:

UPROPERTY (VisibleAnywhere, BlueprintReadOnly, Category =“Components”, meta = (AllowPrivateAccess = “true”))

I haven’t, I’ll give that a go now, but what I can’t understand if this is the case is that the tutorial I’m following was able to successfully compile with the exact same setup in vscode.

I’m also guessing I’ll need to have this UPROPERTY set to all components that I create?

That is what I have:

private:

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category ="Components", meta = (AllowPrivateAccess = "true"))
	UCapsuleComponent* CapsuleComp;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	UStaticMeshComponent* BaseMesh;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	UStaticMeshComponent* TurrentMesh;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	USceneComponent* ProjectileSpawnPoint;

but I left this course to go to the old one, because I was lost, but I am just at the beginning of the old one, so I can’t help more. I know I had an error without the UPROPERTY defined, but I don’t remember if it was the same error.

With the uproperties set, still no luck, still getting the same error. Thanks anyway for taking your time to try and help, it was greatly appreciated. Good luck on your journey :slight_smile:

1 Like

I think I have reproduced your error. Did you include the CapsuleComponent.h?

#include "Components/CapsuleComponent.h"
3 Likes

Thank you so much, it worked!
The tutorial said to reduce the amount of includes by using forward declarations, so instead of the include, I did.
class UCapsuleComponent;

I can’t thank you enough, I thought almost thought it was a dead end :smiley:.
Have a great day!

1 Like

Great day to you too. And good luck!

1 Like

That should still be done. Forward declare in the header, include in the cpp.

1 Like

Ah, I seem to forgot to include it in the .cpp file.
Thanks!

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

Privacy & Terms