I keep getting the error message: Invalid class attribute: Creating actor instances via the property window is not allowed. Is the EditInlineNew specifier not allowed to be used as a class specifier of a class derived from AActor?
here is my class declaration:
Iâve not tried it, but I would actually be a little surprised if you could use it that way. To quote the documentation:
But spawning an Actor is something with a great many more fiddly details than just constructing an arbitrary UObject; thereâs more scaffolding needed to make an actor⌠well, âexistâ, for lack of a better term.
(Hence the difference between âcreatingâ an instance of some UObject subclass, versus âspawningâ an instance of an AActor.)
Since creating a new instance of a class in the property window does not have a way to obtain the aforementioned fiddly details from the user, it also has no way to provide that information to the rest of the engine.
(Plus, all that aside, the error message does pretty much say outright âNo, you canât do that specific thing you are trying to do.â It just doesnât really bother to give any hints as to why.)
Alright so no creating instances of actors in the editor. My next question would be: how would you create a list of âitemsâ that reference a base class, in this case my item class?
My goal is to have this list be accessible from ACharacter derived class( my enemy class) and when they âdieâ they randomly choose an item from that list and spawn it into the world.
What Iâm doing now is this:
A data table with 5 TArray of AItem.
This data table information is part of a loot table actor component that I made.
In the loot table actor component I have a reference to the ACharacter that owns it.
From the owner I get itâs loot table chooser (basically a enum that selects the data table to use for drops).
Create an array of class references as a property.
Or, perhaps, use a Set instead of Array. That would work, too.
Basically what jwatte said: storing the class rather than an instance.
Consider the fact that an instance of a thing is a single, solitary one â a specific medpack, not the concept of âmedpackâ as an item. Realistically, youâd want to store the concept, so that when you were dropping something, youâd say âI want to drop a thing of this typeâ, rather than âI want to drop this one specific medpack, out of all medpacks anywhere in the world.â
Admittedly, I personally might go a little further than jwatte here. (But Iâve never met a system I wouldnât overthink and try to genericize, soâŚ)
That said, Iâd probably define a data table that could hold weighted lists of possible loot. Each row in the table would hold a TSubclassOf<AItem>
â a reference to the class, rather than an instance â and an integer value for the âweightâ, with bigger numbers making it more likely that the item drops.
(If youâve got quality levels or quantities, Iâd probably add a minimum quality/max quality or minimum quantity/max quantity, too.)
Then I could build multiple âloot tablesâ; if I had a âgeneral trash mobâ table, I could use it on a bunch of different types of trash mobs, versus, say, a âminibossâ table that had better drops. And when something died, Iâd take the loot table for that character, use the weights to pick an item from the list, and get a resulting subclass of your AItem class. Then, in code, I could easily just use that class with SpawnActor
to spawn in a specific instance of that type of thing at the appropriate location.
Which is functionally handling this as âcreate a medpack and drop it hereâ, versus âtake this one specific medpack from wherever it might be in all of existence, and move it to this spot.â
We hope this Blueprint Class âEditInlinenNewâ plugin (which no longer requires any C++ to use the EditInlinenNew feature) will help you.
https://www.unrealengine.com/marketplace/en-US/product/blueprint-editinlinenew