Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Can't set pointer to derived type

I'm making a test pawn class, and creating a component inside. In the header file I put:

 USceneComponent* mySceneComponent;    

and in the cpp:

      // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
     mySceneComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));

But i get the error :a value of type "UStaticMeshComponent " cannot be assigned to an entity of type "USceneComponent "

Doesn't UStaticMeshComponent inherit USceneComponent? Am I misunderstanding something? I am perplexed.

Product Version: UE 4.10
more ▼

asked Jan 13 '16 at 07:32 AM in C++ Programming

avatar image

1 2 1

avatar image zachfm Jan 13 '16 at 07:34 AM

Just to clarify, that's not ALL that's in those files. I just included the relevant snippets, and didn't realize it would put line numbers like that. Let me know if I'm leaving out anything important.

avatar image ScotShinderman Jan 13 '16 at 06:25 PM

I tried the exact code you have above and it compiled and runs fine. This was as a member variable with parent class UActorComponent;
Perhaps it needs a clean + build so the generated file is recreated? The only other thing that comes to mind is it's somehow picking up a override, perhaps with a default template parameter? Mac10.11.2,Xcode7.2,Unreal 4.10.2

avatar image Jan 13 '16 at 09:22 AM

Hi Zachfm,

you must use the exact class type for every member that are flagged as UPROPERTY, otherwise the Blueprint magic won't work.

This is inherent to the way UE4 macro work: UPROPERTY will parse the next line and generate blueprint access (read/write...) functions according to the class.

Hope it helps,

avatar image cancel Jan 13 '16 at 09:26 AM

Is that true in all cases, or only for properties which are flagged as accessible to Blueprint?

avatar image Jan 13 '16 at 09:27 AM

It looks like it's only for UPROPERTY, the error must come for the UBT

avatar image TTaM Jan 13 '16 at 02:45 PM

What Co said is not true. You can assign any subclass of a variable type to the variable and the UPROPERTY will still function.

Have you tried casting the result of the component creation to USceneComponent* ?

avatar image zachfm Jan 13 '16 at 05:50 PM

I tried an explicit static cast and it said there was "no known conversion"

avatar image zachfm Jan 13 '16 at 05:59 PM

Thanks for your answer, Co

I was following this little tutorial when I did this: https://docs.unrealengine.com/latest/INT/Programming/Tutorials/PlayerInput/1/index.html

It looks like they do exactly this in the third step of the tutorial. Maybe I'm missing a setting somewhere or some nuance that's allowing them to do this? Is there any difference between their code and mine that i'm not realizing?

avatar image Jan 13 '16 at 06:15 PM

You can try this (but it's ugly):

 mySceneComponent = Cast<USceneComponent>(CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent")));
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question