x

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"

How to let sub classes override components.

I have a base class with a component of some abstract type. Then I have a subclass that needs to use a specific type.

Is this possible? So far the things I've tried resulted in runtime errors on startup.

Product Version: Not Selected
Tags:
more ▼

asked May 17 '14 at 08:52 AM in C++ Programming

avatar image

illYay
340 27 41 50

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Ah I figured it out!

Thanks to this question:

https://answers.unrealengine.com/questions/851/crash-cant-override-movement-component-twice-for-a.html

This was very confusing at first, but I ended up doing something like this:

 AMyGamePhysicsItem::AMyGamePhysicsItem(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP.SetDefaultSubobjectClass<UStaticMeshComponent>(TEXT("WorldCollision")))
 {    
     UStaticMeshComponent * WorldCollisionMesh = Cast<UStaticMeshComponent>(WorldCollision.Get());
 
     //make the world collision mesh not visible and set up all the networking and physics stuff
     if (WorldCollisionMesh)
     {
         WorldCollisionMesh->SetVisibility(false);
         WorldCollisionMesh->SetIsReplicated(true);
         WorldCollisionMesh->SetSimulatePhysics(true);
         WorldCollisionMesh->SetCollisionProfileName(TEXT("ItemWorld"));
         WorldCollisionMesh->bGenerateOverlapEvents = false;
         WorldCollisionMesh->GetBodyInstance()->SetInstanceNotifyRBCollision(true);        //generate hit events    
     }
 }

PCIP.SetDefaultSubobjectClass returns a PCIP so you can string multiple SetDefaultSubobjectClass together inside the super constructor.

And if anyone's wondering, this was code to have items affected by physics, like guns laying on the ground.

more ▼

answered May 17 '14 at 08:41 PM

avatar image

illYay
340 27 41 50

avatar image Arty-McLabin Feb 11 '18 at 02:43 PM

any clue on how to do this in 2018 and by inheriting in blueprints? i have opened a question here and would love to hear from you! https://answers.unrealengine.com/questions/757117/umeshcomponent-specification-to-skeletalstatic-in.html

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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