RootComponet cannot be assigned to mesh

I just started learning to use Unreal Engine with C++, and while following the C++ Battery Collector tutorial serie on the Unreal Engine channel an error came up.

When attempting to set my RootComponet to my UStaticMeshComponet called BatteryMesh, Visual Studio returned an error saying
a value of type “UstaticMeshComponent *” cannot be assigned to an entity of type “USceneComponent *”

Below are my codes:

//in header file
private:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Catagory = "Battery", meta = (AllowPrivateAccess = "true"))
	class UStaticMeshComponet* BatteryMesh;

 //in constructor
 BatteryMesh = CreateDefaultSubobject<UStaticMeshComponet>(TEXT("BatteryMesh"));
 RootComponent = BatteryMesh; //error here

Any help would be appreciated!

use
SetRootComponent(BatteryMesh);
(Not necessary but good practise)
Also Ignore the error log thats just Intellisense who has trouble understanding UE4 Code. If its Compiling successful you are good to go. If not check the error the Compiler gives you thats the one you can trust :stuck_out_tongue_winking_eye:

Did you ever learn anything about this? I never had this problem before but am experiencing it now for some reason.

Dno if you fixed it already but you wrote “UStaticMeshComponet” instead of “UStaticMeshComponent” notice the extra N at the end!

Componet

------------^

Component

EDIT:

After doing some more searching ( I was having the same issue), I found that this line does the work: USceneComponent(PickupMesh);

Aparently the RootComponent the tutorial talks about was changed or removed and a UStaticMeshComponent can no longer be assigned as a RootComponent. However, while using this it doesn’t show the Static Mesh menu in the "Class Defaults"when double clicking on the Blueprint. So there is still something wrong with the code, any help would be welcome!

Hi,

You can’t assign because it can’t resolve UStaticMeshComponent type.
Include #include “Components/StaticMeshComponent.h” will solve problem.

Thanks.

thanks,its work for me!!!

One way to fix this issue and resolve the problem is to include the right class in the header of the CPP file. After numerous attempts to fix the problem with different ways I solved it by adding

#include “Components/SkeletalMeshComponent.h”
#include “Components/StaticMeshComponent.h”

In the CPP file. It can be assigned to USceneComponent but in order to do so it has to have the correct access path as above. Hope this helps as I can see this issue is a frequent one.

Thanks , it is really helpful.