# How to dynamic cast from any type

**URL:** <https://forums.unrealengine.com/t/how-to-dynamic-cast-from-any-type/2475963>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [April 25, 2025, 5:30pm UTC](https://forums.unrealengine.com/t/how-to-dynamic-cast-from-any-type/2475963 "2025-04-25T17:30:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![swaggod](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/swaggod/32/1051181_2.png) [@swaggod](https://forums.unrealengine.com/u/swaggod)\
**Post date:** [April 25, 2025, 5:30pm UTC](https://forums.unrealengine.com/t/how-to-dynamic-cast-from-any-type/2475963/1 "2025-04-25T17:30:14Z")

</div>

I have a FlattenArray function that returns any so that I can flatten any multidimensional arrays.

```
FlattenArray(Grid : [][]any) : []any =
    var Result : []any = array{}
    
    # Iterate through each row
    for (Row : Grid):
        # Add all elements from this row to the result
        for (Value : Row):
            set Result = Result + array{Value}
            
    return Result

```

However, when I then try to cast these any to creative\_prop type, I get “the Dynamic cast any to `creative_prop`: argument type `any` must be a class.” Searching the documentation I found nothing on how to cast from any type, is this possible? Or can I modify my Flatten array function to specify what type to return?

---

<div class="post-metadata">

**Author:** ![Mayumichi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mayumichi](https://forums.unrealengine.com/u/Mayumichi)\
**Post date:** [April 26, 2025, 3:49pm UTC](https://forums.unrealengine.com/t/how-to-dynamic-cast-from-any-type/2475963/2 "2025-04-26T15:49:13Z")

</div>

Don’t think you can cast back to something from any, but you should be able to do this instead

```auto
FlattenArray(Array : [][]t where t : type): []t=
    var Result : []t = array{}
    
    # Iterate through each row
    for (Row : Array):
        # Add all elements from this row to the result
        for (Value : Row):
            set Result = Result + array{Value}
            
    return Result

```

---

<div class="post-metadata">

**Author:** ![swaggod](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/swaggod/32/1051181_2.png) [@swaggod](https://forums.unrealengine.com/u/swaggod)\
**Post date:** [April 26, 2025, 5:54pm UTC](https://forums.unrealengine.com/t/how-to-dynamic-cast-from-any-type/2475963/3 "2025-04-26T17:54:01Z")

</div>

Amazing thank you!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [May 26, 2025, 5:54pm UTC](https://forums.unrealengine.com/t/how-to-dynamic-cast-from-any-type/2475963/4 "2025-05-26T17:54:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
