[SOLVED]Cant cast an object reference in an Editor Utility to Actor or its class type? What would cause that?

As the title states, I am making an Editor Utility. Specifically an AssetAction Util. I have created a Call In Editor func. I can see it when I right click an my assets in the Content Drawer. When I click it, I have output for Cast failed. I have finally tried just casting to a base actor even, and failed. The Editor Scripting Util plugin is checked for Install. It appears to be on by default these days.
Is it possible the Plugin is checked but NOT actually enabled? Should I check the uproject file or the UnrealEditor.build.cs for something? I am only vaguely familiar with the build system.
I have watched EPICs official videos, looking for some detail I missed. Checked the forums. I don’t see why iterating through my Assets isnt working on cast.
One of the videos mentions that you need to right click the Util and select Run. This appears to be old as you have to create the Run event manually for that to be available. I can’t seem to find anything wrong with my workflow.

I have now created a new AssetAction Util and the new simple func is NOT available when I right click assets… What is going on? Im doing a check in my logs to try to ensure the plugin is being loaded on startup but I’d love another avenue of approach.

Checked my logs. EditorScriptingUtilities is being mounted and loaded or whatever. Then unloaded on shutdown. All good. I don’t see the issue then.

DONT MAKE AN ASSET ACTION UTILITY, ON ITS OWN! You need to follow the given step to make one by selecting an EBP in the BP Wizard THEN selecting Asset Action Util from there. Not sure why a stand alone Asset Action Util doesnt just help you skip a step or 2 during creation but whatever.

An asset is not an actor. Blueprints have their own underlying type UBlueprint, which is basically a template responsible for generating dynamic classes and their objects (actors). When you right click an asset and try to cast to actor (or whatever you are doing I don’t get) chances are you are getting an object of type UBlueprint. You can get the generated class from it :

// UObject* Asset;
if (UBlueprint* Blueprint = Cast<UBlueprint>(Asset))
{
    UClass* Class = Blueprint->GeneratedClass;
    if (Class && Class->IsChildOf<AActor>())
    {
        AActor* CDO = Class->GetDefaultObject<AActor>();
    }
}
1 Like

Yeah even doing that, I still can’t ask that actor for its components. Well I can but I only get the root component. I want all of the components.

I can ADD to the blueprint, like this. I can add a component but I can’t get it back:
FKismetEditorUtilities::AddComponentsToBlueprint( BlueprintObject, NewComponents );
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified( BlueprintObject );
FKismetEditorUtilities::CompileBlueprint( BlueprintObject, EBlueprintCompileOptions::None );

This code works fine but is ultimately what got me into this mess. I was making what cheap scene components but now that I have thousands of these objects with dozens of components, its “OOPS All SceneComponents!” - the game


You can do this same thing in BPs, like this EXCEPT you can’t cast to actor, as you showed in code. I could be missing some other conversion or functionality, but I don’t see where.
I could cast this to an AActor class or its actual base type class but then what? No idea how to work directly with a class and any queries I put in that make sense don’t get me anything. Get the classes Components or something… idk.

Afaik you cannot get or manipulate CDOs from blueprints, you have to use C++ for that.

1 Like

Ok, well I have this equivalent in C++ and the only component I can get is the root/StaticMesh. And I dont see why. Once I call Blueprint->GeneratedClass->GetDefaultObject() then cast that return to my actor type… then what? I can call my objects functions. Cool. Still no components. This is driving me nuts. I tried asking the root for children components. Thanks for the input! I appreciate it.

It seems blueprint-added components are not visible this way. Only native components come out.

From a quick glance it looks like blueprint-added components are instanced later, on construction, right before BP construction script, using SCS (Blueprint->SimpleConstructionScript). The SCS is not inherited, so if you want to figure out the complete tree for a given blueprint, you’ll have to walk up the chain of blueprint parents and iterate the SCS for each of them.

Is that what this is doing?

I’m about to try to implement this. Pretty solid set of code there.

Im a little stuck on casting my ActorClass to UBPGeneratedClass but I’ll gt there

Super weird behavior. It gives me 2 more components and I have NO idea why those 2. Progress but… what the hell. I did notice, as Chatoullie said, it appears that blueprint-added components are not visible. Im not sure how…
Ok as I wrote this I went and checked one other thing. There is a filter section where the code does an if(NodeItr->IsA(ComponentClass)
I dont need that. I’ll filter by tag, after I get EVERY COMPONENT. FINALLY! God this was a ridiculous effort to get a list of components but dang it we got there.

A completely working example of cast to class, blueprint’s only. Just if anybody still looking for the solution

3 Likes