Can I convert "FKShapeElem" to "FKSphylElem"?

So first of all let me tell you that my C++ skills are relatively basic (no pun intended). So it could be that I didn’t understood some things that could be related to C++. But I also know that UE does handle things quiet differently regarding C++ so… I hope someone here can help me!

Now to what I am trying. I would like to know IF and HOW (if possible) I can convert “FKShapeElem” to “FKSphylElem”?

What I want is to filter out informations out of “FKSphylElem” by iterating through the elements and filter an element by a specific “name”. Here is the StaticMesh-View in Editor where the informations are set:

The problem is, that the “FKSphylElem” does not have the “Name”-Value, but as i understand right through the documentation “FKShapeElem” does. Futhermore, as i understood right, according to the UE-Documentation, the “FKShapeElem” is a parent class of “FKShapeElem”:

So it should be possible to iterate through the list of “FKShapeElem” in “UStaticMesh->FKAggregateGeom”, finde the specific “FKShapeElem” with the desired “name” and finally convert the “FKShapeElem” to a “FKSphylElem” and finally filter out the needed informations!

But when I try to convert/cast “FKShapeElem” to “FKShapeElem” and compile my code, the compiler throws errors. Here is my current try on filtering the informations out:

grafik

The compiler tells me that the cast/convert was not successfull:

error C2440: “Initialising”: “To *” cannot be convertet to “FKSphylElem”
with
[
To=FKSphylElem
]

Also trying to set the variables as pointers didn’t work, but that are the part of C++ that I am very weak right now.

So what am I missing here? What am i doing wrong? Is what I want even possible? And why the f* is the name not put into “FKSphylElem” instead of “FKShapeElem”?!?!?!

Uh this is funny. I figured it out myself and it realy. was. just. one. function!

Instead of using “Cast” without pointer…

FKSphylElem capsule = Cast(geom.GetElement(i));

I had to use static_cast with pointer:

FKSphylElem* capsule = static_cast<FKSphylElem*>(geom.GetElement(i));

Hope anyone with similar problems will find revelation with casting problems.

Anyway, would be grreeat if anyone can explain to me what happened here and if i “need” to use “static_cast” or would i be able to use “Cast” too in another way?

Cheers.

Hi there @OppaAi,

Hope you’re well and having a great week so far!

This topic has been moved from International to Programming & Scripting: C++.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! :slight_smile:

1 Like