How to write class names in a console command?

I’m making custom console commands to help me with developpemennt and I have a /ce give [item] and the item is a class but if I just write the class name it doesn’t work. How should i do it?
image

Unfortunately this isn’t possible directly. You’ll have to accept a string instead and parse it.

In C++ this is easy-

UClass* ActorClass = FindObject<UClass>(ANY_PACKAGE, *ClassName);

But in blueprints you’ll have to manually iterate through the items to see if the class’ name is the same as the string.
Or through this method you could instead check against the item’s display name- might be easier for you in-game.

It should be possible.
If you are writing C++ class, remove the U prefix for your UItem class (eg: USomeWeapon → SomeWeapon)
If you are writing a BP class, add _C postfix to the blueprint asset name (eg: BP_SomeWeapon → BP_SomeWeapon_C)

Note however that for blueprints it is not guaranteed to work as it will only find classes for assets that are already loaded in memory. If they are not, you’ll have to load then via a call to LoadObject or LoadClass (or the async load methods), and they require full asset path.

1 Like