# C++ Can anyone see where I have gone wrong? Unreal, 1 error in class

## Recommended Posts

This is from the unreal tutorial battery collector c++.

I'm learning unreal and am new to it so i couldn't guess why this is happening. Is it clear to anyone what i have to do to fix this?

##### Share on other sites

Your error says that your trying to assign a mesh as a Scene Component

PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
RootComponent = PickupMesh; //This is where you make the mistake. A mesh != a object.

Look at the tutorial again and see what they do at this point.

##### Share on other sites

That's strange, we do the same thing in our project (assign a UStaticMeshComponent to RootComponent), and it works fine. UStaticMeshComponent inherits from USceneComponent, so such assignment is valid.

Does it work, if you do an explicit cast?

RootComponent = (USceneComponent*)PickupMesh;

Don't know, if it has anything to do with the problem, but it looks like you're using an older version of Visual Studio (2013?), while they recommend VS2017 for UE4.18 (although we use VS2015 without any issues).

UPDATE: I guess, it doesn't immediately follow, that the assignment of UStaticMeshComponent* to USceneComponent* is valid, only that a cast from UStaticMeshComponent* to USceneComponent* is. And unfortunately I'm not the right person to explain, whether such cast will happen implicitly, and what kind of constructor you need in order for it to happen.

Edited by dietrich

##### Share on other sites

@Scouting Ninja and @dietrich thank you for replying. I really appreciate the posts. I had to go and work later that day when I made my thread so I was unable to reply any sooner. I will try out what has been mentioned here and shall let you know how I get on. Thanks for the feedback.

edit: I'm using VS'15 btw.

Edited by GameDevCoder

## Create an account

Register a new account

1. 1
2. 2
JoeJ
14
3. 3
4. 4
5. 5
frob
11

• 13
• 16
• 13
• 20
• 12
• ### Forum Statistics

• Total Topics
632178
• Total Posts
3004603

×