Announcement

Collapse
No announcement yet.

Construct Object From Class - "Wrong class to spawn" error - Initializing objects via blueprint

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

    Construct Object From Class - "Wrong class to spawn" error - Initializing objects via blueprint

    Hi guys,

    I've created a C++ class called "Item" that holds an array of another class of mine, named "ItemEvent". This works fine if I add events via C++, but for ease of use I'm trying to enable the addition of events via blueprint also.

    I have several blueprints that derive from "item". Item has a function named "AddEvent" which accepts a pointer to an ItemEvent and simply adds it to the existing TArray. My issue is that, when I create new variables in my blueprint of my various ItemEvent types, they are never initialized by default.

    I have begun trying to call the following node on the BeginPlay event to initialize these objects: https://docs.unrealengine.com/latest...***/index.html

    My issue is that this does not work, and provides the following error:
    Click image for larger version

Name:	7779694065857039bf9d46bb488c709a.png
Views:	1
Size:	63.6 KB
ID:	1197134

    The object "SwingOneHandedWeaponEvent" is a really simply C++ class derived from ItemEvent. No matter which class I pick here, I seemingly always get the "wrong class to spawn" error.

    Am I going about this incorrectly? All I wish to achieve here is to initialize the variables that I include on my blueprint when the object is created at runtime, so when I access them later they are not null.

    Any and all help would be greatly appreciated!

    #2
    Construct Object will only create anything derived from UObject, up until a certain point (Like Actor cannot be spawned from Construct Object). Which base class does ItemEvent come from?
    Marketplace code plugin: AesTargeting - Make your Actors targetable =)

    Comment


      #3
      It's derived from ActorComponent. Is that not valid?

      Comment


        #4
        I haven't used the Add x Component node before, but I think it is the node that you're looking for. Simply type in the context menu: Add SwingOneHandedWeaponEvent component.

        Samples of my own actor components written in C++ (The add nodes were auto generated): http://puu.sh/rONPo/236664ca5f.png
        Marketplace code plugin: AesTargeting - Make your Actors targetable =)

        Comment


          #5
          Great - that set me on the right track. I simply needed to expose my cpp classes to be blueprint spawnable and that node then became available. Thanks

          Comment

          Working...
          X