Download

How get child class from parent in code

Very very new to UE4, less new to C++, so I know this is a really stupid question but a few days of Googling hasn’t helped so I’m hoping someone here can help.

Wrote a script for an OpenDoor component class, which works fine when dealing with a simple standalone door mesh, but now I’m trying to apply that code to a blueprint whose parent is both the door and frame, and whose children are the doors. I’m not familiar enough with Blueprint yet to get into that, so I wondered if there was a way you can go from GetOwner() to something like GetChildBy Name(“NameOfChild”) so I can access the doors only instead of the whole collective mesh.

I apologise in advance for any stupidity/incorrect terminology.

If you want to access only the door mesh components in C++, you can keep pointers to those as class properties when setting up in the constructor. You can then access those properties easily anywhere you have an actor reference, or encapsulate door behavior in public actor class functions.

If you’re using a blueprint and have a class that extends the actor which contains your door components, just drag those door components into your blueprint event graph. You can then create events that can be called from other blueprints that can use those door components.

Thanks for this. I’m sure it’s spot on but I just don’t know how to d what you’re suggesting. I think that’s a sign that I stop trying for now :slight_smile: