# Casting one (parent) class to another (child) class issue

**URL:** <https://forums.unrealengine.com/t/casting-one-parent-class-to-another-child-class-issue/2512575>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [May 16, 2025, 2:36am UTC](https://forums.unrealengine.com/t/casting-one-parent-class-to-another-child-class-issue/2512575 "2025-05-16T02:36:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DogOnAKeyboard13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DogOnAKeyboard13](https://forums.unrealengine.com/u/DogOnAKeyboard13)\
**Post date:** [May 16, 2025, 2:36am UTC](https://forums.unrealengine.com/t/casting-one-parent-class-to-another-child-class-issue/2512575/1 "2025-05-16T02:36:35Z")

</div>

Heyo,

I have this class function in a child/sub class called itemBox. It inherits from the parent/super class spawnableThing. Both have a function called Spawn\_this, and it’s overridden in the itemBox child class. In that function I try to cast a creative\_object (which could be teleporter devices, collectible\_object\_devices, anything Fortnite offers as a device…) to the more specific collectible\_object\_device to do specific functions from that collectible object class. Does anyone know about using classes within classes and parent-child (super-subclass) relationships and why I can’t get the Show() and RespawnForAll() functions of collectible\_object\_device to actually work?

Notes:

- I made this class called `spawnableThings`
- `spawnableThings` has a `creative_object` optional variable called `spawnableDevice`
- in the function I try to cast the `creative_object` variable named `spawnableDevice` as a `collectibe_object_device` in this case to do more specific things, such as call Show() and RespawnForAll() (which are methods of `collectible_object_device` )

Here is some simplified reduced code that I made to help show what I’m doing:

```auto

# ===================================
# spawnable Thing class
# ===================================

spawnableThing := class<unique><concrete>:
    # parent class for spawnable things like item boxes, teleporter class, etc.
    # idea was to store any creative device from Fortnite's selection, like collectible object device, teleporter device, etc and then handle general shared things like "teleport to new location" functions without writing those individually in sub classes

    var spawnableDevice<protected> : ?creative_object = false

    # class functions ----- 
    Spawn_this<public>(itemManager_counter : itemManagerStats, newSpot : spawnableSpot):void =
        # "spawn" this object by moving it from original position to new position
        # note: specific devices like collectible objects should hide / unhide in their own overrided function of this function

        # moving object will be done by spawnableSpot function
        # hiding / unhiding object will be done in specific object subclass overridden method
        # here, we just set the objects status flags and timer

# ===================================
# itemBox class
# ===================================

itemBox := class<unique><concrete>(spawnableThing):
    # class for holding item box info, which is a collectible_object_device that players can collect

    # class variables
    var isSpecial<private> : logic = false

    # class functions ----- 
    Spawn_this<override>(itemManager_counter : itemManagerStats, newSpot : spawnableSpot):void =
        # "spawn" this item box object

        # moving object will be done by spawnableSpot function
        # here, we unhide the object / respawn it
        if (thisCollectibleDevice : collectible_object_device = collectible_object_device[spawnableDevice?]):
            thisCollectibleDevice.Show()
            thisCollectibleDevice.RespawnForAll()
            (super:)Spawn_this(itemManager_counter, newSpot) # calls super class version of spawn function to finish setting flags

```

I’m particularly trying to verify this part is working

```auto
        if (thisCollectibleDevice : collectible_object_device = collectible_object_device[spawnableDevice?]):
            thisCollectibleDevice.Show()
            thisCollectibleDevice.RespawnForAll()
            (super:)Spawn_this(itemManager_counter, newSpot) # calls super class version of spawn 

```

---

<div class="post-metadata">

**Author:** ![DogOnAKeyboard13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DogOnAKeyboard13](https://forums.unrealengine.com/u/DogOnAKeyboard13)\
**Post date:** [May 16, 2025, 5:32am UTC](https://forums.unrealengine.com/t/casting-one-parent-class-to-another-child-class-issue/2512575/2 "2025-05-16T05:32:21Z")

</div>

Ok my bad guys xD I had something else going on that made the collectible object hidden at the start of the game, and I didn’t realize it until now that it was messing with my debug test results lol. It happens but everything appears to work so far!
