Jump to content
  • Advertisement

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 this post

Link to post
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 this post

Link to post
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 this post

Link to post
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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!