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"

Change USkeletalMesh to UPoseableMesh in C++

Hello

In simple words, my aim is to simply change USkeletalMeshComponent into UPoseableMeshComponent. I need it to do in C++, not in BP.

Here I use First Person C++ Template and change code of

MyProjectCharacter.h file:

 class AMyProjectCharacter : public ACharacter
 {
     GENERATED_BODY()
 
     /** Pawn mesh: 1st person view (arms; seen only by self) */
     UPROPERTY(VisibleDefaultsOnly, Category=Mesh)
     class USkeletalMeshComponent* Mesh1P;
 (...)
     
     public:
     /** Returns Mesh1P subobject **/
     FORCEINLINE class USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; }
 (...)
 }

into:

 class AMyProjectCharacter : public ACharacter
 {
     GENERATED_BODY()
 
     /** Pawn mesh: 1st person view (arms; seen only by self) */
     UPROPERTY(VisibleDefaultsOnly, Category=Mesh)
     class UPoseableMeshComponent* Mesh1P;
 (...)
     
     public:
     /** Returns Mesh1P subobject **/
     FORCEINLINE class UPoseableMeshComponent* GetMesh1P() const { return Mesh1P; }    
 (...)
 }

and MyProjectCharacter.cpp file:

 AMyProjectCharacter::AMyProjectCharacter()
 {
 (...)
     // Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)

    Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P"));

 (...)
 }

into:

 AMyProjectCharacter::AMyProjectCharacter()
  {
  (...)
      // Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)
 
     Mesh1P = CreateDefaultSubobject<UPoseableMeshComponent>(TEXT("CharacterMesh1P"));
 
  (...)
  }

Unfortunately it's not as simple as it might seem. That modification creates errors, that I can't solve with my knowledge.

I'll be very grateful for your help.

Product Version: UE 4.21
Tags:
more ▼

asked Jan 09 '19 at 01:40 PM in C++ Programming

avatar image

gmachnik
3 1 2

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

What you're trying to do won't work the way you've been trying to go about it.

Taking things back a step, it appears you're trying to make a custom pawn actor that works like the ACharacter class but uses a poseable mesh instead of a skeletal mesh. Part of the problem is, the ACharacter class has its own USkeletalMeshComponent built in to it, which means if you derive your custom pawn from ACharacter, your subclass is going to have a USkeletalMeshComponent by default.

You're probably going to need to disable the ACharacter's USkeletalMeshComponent so you can add a UPoseableMeshComponent in its place.

To do that, you're going to need to use the FObjectInitializer, along with the DoNotCreateDefaultSubobject function, in the constructor for your custom character class. Here's how your updated constructor would look in your .cpp file:

 AMyCustomCharacter::AMyCustomCharacter(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer.DoNotCreateDefaultSubObject(ACharacter::MeshComponentName)))
 {
     // Regular constructor stuff goes here
 }

That will prevent the character's default USkeletalMeshComponent from being created when your actor is constructed.

Now you just need to add back in your desired UPoseableMeshComponent, much like you were already doing. Define your UPoseableMeshComponent in your header file:

 UPROPERTY(VisibleDefaultsOnly, Category=Mesh)
 class UPoseableMeshComponent* PoseableMesh;

And then put something like this in your updated constructor:

 PoseableMesh = CreateDefaultSubobject<UPoseableMeshComponent>(TEXT("CharacterPoseableMesh"))

(Like I said, you already had this part figured out, so it should look familiar.)

With that, your custom character should have a poseable mesh component instead of its default skeletal mesh component.

Of course, you can also add back in your getter functions as desired.

Hopefully this gets you closer to a working solution!

more ▼

answered Jan 09 '19 at 05:15 PM

avatar image

the_batch
1.2k 4 5 8

avatar image gmachnik Jan 09 '19 at 10:54 PM

Thank you for the answer. Unfortunately, I still have problem with compilation and this is my log:

 [1/3] MyProjectCharacter.cpp
  C:\UE_4.21\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(84): error C2027: use of undefined type 'UPoseableMeshComponent'
  d:\myproject\source\myproject\MyProjectCharacter.h(22): note: see declaration of 'UPoseableMeshComponent'
  d:\MyProject\Source\MyProject\MyProjectCharacter.cpp(39): note: see reference to function template instantiation 'TReturnType *UObject::CreateDefaultSubobject<UPoseableMeshComponent>(FName,bool)' being compiled
             with
             [
                 TReturnType=UPoseableMeshComponent
             ]
     C:\UE_4.21\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(85): error C2440: 'static_cast': cannot convert from 'UObject *' to 'TReturnType *'
             with
             [
                 TReturnType=UPoseableMeshComponent
             ]
     C:\UE_4.21\Engine\Source\Runtime\CoreUObject\Public\UObject/Object.h(85): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
  

avatar image the_batch Jan 10 '19 at 12:09 AM

Did you include Components/PoseableMeshComponent.h in your .cpp file?

(comments are locked)
10|2000 characters needed characters left
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