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"

Custom USceneComponent (or alternative)

I have a cube that derives from Actor and this cube has 6 walls. Now every wall is a StaticMeshComponent but I need to make it a class (or struct) instead so that I can later replace one of those walls with another class (like a class that has a double-door or something). But from what class do I derive?

  • USceneComponent: Does not work: https://answers.unrealengine.com/questions/743194/howto-add-staticmesh-to-scenecomponent.html Either an undocumented feature from UE4 or an UE4-bug. But this would have been the logical choice.

  • AActor: I don't think that it would be a good idea to make every wall an actor (so 7 actors per cube) for performance reasons and such.

  • UActorComponent: Has no position in the world.

  • UObject: This could in theory work but, I believe that it doesn't automatically replicate and I can't store any UStaticMeshComponents in it. It bugs UE4 out. Apparently when you have a UStaticMeshComponent placed in say Actor X and then store a reference to that component in another actor or UObject, UE4 will randomly crash and/or not render it. I think UE4 get's confused between the pointer and the real object because they are the same in c++ code.

I tried everything I know, nothing seems to work.

Product Version: UE 4.18
Tags:
more ▼

asked Jan 17 '18 at 07:06 PM in C++ Programming

avatar image

Napoleonite
595 91 104 155

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

1 answer: sort voted first

You should derive from USceneComponent - I believe any other option is basically incorrect.

I read the question you linked and tested it for myself, and in a new project it seems to just work as I expected. Were you also seeing the same crash?

more ▼

answered Jan 17 '18 at 10:17 PM

avatar image

alejrb
31 2 1

avatar image Napoleonite Jan 18 '18 at 06:23 AM

Thanks I got it to work, my test code:

 PrimaryComponentTick.bCanEverTick = false;
 
     this->SetMobility(EComponentMobility::Static);
 
     SMC = CreateDefaultSubobject<UStaticMeshComponent>(FName("PleaseDontCrash"));
     SMC->AttachToComponent(this, FAttachmentTransformRules::KeepRelativeTransform);
     SMC->SetMobility(EComponentMobility::Static);
     SMC->SetStaticMesh(ULib::CreateObject<UStaticMesh>(P_WALL_MESH));

But then I have no idea why it crashed before. But I'm not gonna complain, the code is and was good then. Thanks!

P.S. Also make sure to add this line:

 UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )


(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