Struct alternative with inheritance?

I’m creating an odd state machine for my character to manage their actions and need a data structure that simply holds data, supports inheritance, and can be modified at run time. In normal C++ I could just do this with a class but I’m still unfamiliar with the UE environment and intended structure of things, also my project is all blueprints so far and I would like to know if there is a built in solution to this I am missing.

My basic intention is to have a BaseAction abstract class that holds one variable. Then I could make classes from that adding variables related to that action. Then character can use the BaseAction as a variable to hold the different actions and change the action’s data until a new action is set.

I just need basically a struct but with inheritance. I looked at using classes but none of them seem to be a good fit. Actor is definitely not right, Actor Component is close but these just need to be variables and not full on components. I tried Primary Data Asset and making children of that which seems close too but I don’t see how to construct them at run time, also from what I gather they are more fixed data for objects in game.

Is there a data structure I’m missing? Any suggestions?

data structure that simply holds data, supports inheritance, and can be modified at run time

  1. You can spawn Actors, Add Actor components, Add Elements to Arrays, Maps, Sets at Runtime. Use a Reference to a Parent object to simulate inheritance or copy data from a Parent object.

  2. Another alternative is to store the info a structured text format like JSON and develop encoder/decoder to use the information in the format.

  3. Eliminate the need to support inheritance.

Thanks but without inheritance I can’t solve the issue as I intend to leverage polymorphism. Using text or JSON would be needlessly complicated and add too much over head. I have now tried using actor component as a base class with children but this still seems wrong, like using the wrong tool to solve a problem. I think my best bet may just be a custom C++ class at this point but I was trying to avoid that for now.

Instead of Actors, try using Objects. The very base class for everything in UE.
They are more lightweight than actors as they don’t have any transform, rendering, physics, etc.
They support inheritance and construction at runtime.

2 Likes

I failed to include Objects in my list of constructs you can create at runtime. But i think this is a design-time problem.

I'm always interested in others approach to AI other than Behavior Trees.

An Odd State Machine captured my attention.

I’m working on a Rules-based AI subsystem myself. But I’m engineering it to be designed and edited at in-game at runtime in a collaborative manner.

I’m glad I checked back here before getting all set up with C++, I was just about to and looking into the best class to inherit from.

So I have always seen Object in the list that comes up when creating a BP class but I always thought it was just a drop down, not an actual selectable class. I also thought it odd that UE would have that class but not make it accessible. I was just missing that I could actually use it. This was exactly what I needed.

I was also stumped on how to use it in BP, specifically creating it. Turns out it’s just “Construct Object From Class” node.

These are obvious things I just missed. Now I feel dumb.

just note Objects dont replicate by default and cant be saved

1 Like

For now this is fine. Its just a side project of mine. Saving is not necessary for this. As for replication I’ve never made anything for online play but that will be a hurdle I tackle later.

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