When to create Sub-Objects of a blueprint class
I am trying to code a modular weapon system. The weapon is an Actor with a number of components that are responsible for different parts of the weapon.
Each component would have events that are fired when, say the weapon is fired, or reloaded etc. Ideally I would like to be able to subclass each component in blueprints to allow for custom behaviour and then just put them together in the Weapon blueprint, but I know that you cannot change the class of a Component.
Instead I decided that each component would have a assignable sub-object that actually did the heavy lifting of the class.
That way I could just subclass the manager in blueprints, and set the "AmmoManagerClass" variable to be the blueprint that I want to use.
I now have two questions:
I can't spawn it in the constructor as the value of AmmoManagerClass wouldn't have been set in the editor yet. I tried creating the Manager in the PostInitProperty() and InitializeComponent() functions, but the normal ways of creating UObjects (ConstructObject()) caused the engine to crash with the error: "class object none was created in UWeaponAmmoComponent instead of package".
I'm sort of all out of ideas at the moment, any help would be much appreciated.
The two errors I'm getting are:
Which happens when I use this in InitializeComponent() in the AmmoComponent:
Which happens when I use this in the same function:
But this one happens after I stop the test whereas the first one is a soon as I start it.
I managed to fix the problem, or more like I just changed it. I added the EditInlineNew specifier to the AmmoManager, and just had a pointer to it from the weapon actor that was specified as Instanced. This let me create an instance of any subclass of AmmoManager directly from the defaults tab and I could do away with the AmmoComponent altogether.
answered Jan 11 '15 at 04:14 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here