Announcement

Collapse
No announcement yet.

Is it possible to create an Array of Classes?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is it possible to create an Array of Classes?

    The title pretty much says it all.
    Essentially, I've got an Enum in my game that's got names of 5 different classes. I want to be able to access the appropriate class based on which Enum value is selected and spawn an object of that class. Right now, the only way I know how to do it is through Branch checks, but I think Arrays would be more efficient.
    However, I haven't been able to find a way to create an Array of classes, so if anyone knows how to do that, I'd really appreciate the help. Thanks a lot.

    #2
    Hey,
    you can use a map to do that. Use the enumeration as key and the class as value.

    If you are replicating the array you have to take other solutions, because you can not replicate maps.
    Attached Files
    Products: Damage, Stat and Resource System, Inventory System Support/Contact: Discord/E-mail
    Documentation: Synware

    Comment


      #3
      Yes, you can create an array of classes just like with any other variable type. You just need to make sure that all your 5 different classes can be derived from this particular class that you're using as the variable type.

      For example, if all of your classes can be placed in the level as actors, then you can set the Actor class as the variable type. It will then allow you to populate the array with any class derived from Actor.

      Edit: But Synia's approach is more recommended. You can directly access each class with the enum without any additional logic.
      Last edited by Stormrage256; 09-23-2019, 09:55 AM.
      Unreal Possibilities
      Wave Spawning System | Tower Defense Starter Kit | Floating Damage Texts

      Comment

      Working...
      X