How am I using EditInlineNew UCLASS Specifier wrong?

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:
image

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.

image

Or, perhaps, use a Set instead of Array. That would work, too.

1 Like

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.”

1 Like

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