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"

Casting to USkinnedMeshComponent works differently for Static/Skeletal meshes

I Have a superclass Equippable which requires a USkinnedMeshComponent in order to function. I would like to be able use either UStaticMeshComponent or USkeletalMeshComponent in my subclasses, since different types of objects have different animation requirements.

However, I'm having some trouble regarding casting. I was originally just trying to cast the root component to a skinned mesh component, but was unsuccessful, so I'm now simply setting a USkinnedMeshComponent* in the constructor of each subclass. To do that I'm using the following function:

 void AProxyWarEquippable::SetRootMesh(USkinnedMeshComponent* NewRootMesh) {
     RootMesh = NewRootMesh;

Which works fine... if NewRootMesh is a USkeletalMeshComponent. If it is a UStaticMeshComponent, however, I need to use this function:

 void AProxyWarEquippable::SetRootMesh(UStaticMeshComponent* NewRootMesh) {
     RootMesh = (USkinnedMeshComponent*)NewRootMesh;

In the latter example, I must cast NewRootMesh using that syntax. If I use Cast(NewRootMesh) in this case, it returns null.

I read somewhere (in presumably old documentation that I am now unable to find) that both of these classes extended the skinned mesh component, which is why I'm attempting to do this... but I'm now realizing that according to the latest docs, UStaticMeshComponent actually does not extend USkinnedMeshComponent. This would explain the casting issue. It does not explain, however, why I'm still able to cast my static mesh to a skinned mesh using this syntax. It seems to work just fine. Can anyone explain to me why this would be the case?

Product Version: UE 4.13
more ▼

asked Oct 17 '16 at 05:56 PM in C++ Programming

avatar image

337 10 21 39

(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