How to create editor for custom class derived from AActor?

Hello,

I am making a plugin in which there is class(ABActor) which is derived from AActor, now when I import certain stuff, I create asset of this class in contain browser. There is no mesh or any thing attached to this asset.

Now when I double click this asset/package and try to open it, UE4 crashes, I guess it is because there is nothing to open i.e. no editor is attach with this custom actor class of mine.

So what can I do to fix this issue ? Is there anyway to create editor for custom actor class, which will open when i double click this asset ?

Please refer the attachment for more info.

Thanks

What is your setup exactly because it seems confusing? Here issues i see:

Actors can not be assets, engine don’t expect actors to be used that way, engine insted expect to have actor class which you spawn in the world. In fact AActor can’t be used as asset from simple fact it needs a UWorld instance to exist, and assets are instantiated objects not classes, so when you attempt to open it editor littlely tries to spawn the actor and might be reason why you get crash

Way asset normally work is that you have asset Class like UStaticMesh, you got a component class which manifests asset in actor like UStaticMeshComponent. Scene components are once reproducible for manifesting physical assets in to the level, but they don’t need to have component as asset can be simple data container which you set in property editor in some actor for example. And finally a dummy actor like AStaticMeshActor which is most simple actor containing component for asset, which is spawned when you drag and drop the asset, this is defined in UActorFactory and it does not need to spawn dummy actor like that it can preform other actions when you drop the actor on to viewport.

So in you case, you should have asset object class, like UBActorTemplate containing data or whatever, and have if not component then at least actor ABActor which will have a pointer to the asset and do something with it, have a UActorFactory which will spawn ABActor when UBActorTemplate is dropped

The reason why you get crash i think might be related is because you attepting to AActor as asset (atleast i think), because normally default behavior for asset in content browser is to open it in property editor (same as data asset does, data asset was actully made to make asset types simplier without making AssetTypeActions and UFactory). So you should not have any crash, the reason is elsewhere.

You can override that default behavior AssetTypeActions by overriding OppenAssetEditor function:

It generally should open editor, but it can do practically anything, is simply executed when you double click the asset. But again this is optional, if you don’t override that function, asset will be opened in simple property editor, showing all exposed properties, here the default code from FAssetTypeActions_Base:

virtual void OpenAssetEditor( const TArray<UObject*>& InObjects, TSharedPtr<class IToolkitHost> EditWithinLevelEditor = TSharedPtr<IToolkitHost>() ) override
{
	FSimpleAssetEditor::CreateEditor(EToolkitMode::Standalone, EditWithinLevelEditor, InObjects);
}

Now at this stage of thing you doing, you should not “guessing” why things crash, you should have ability to figure out why crashes yourself, either by checking the logs in Saved/Logs in your project directory or by running debug in VS. It is rare to see engine to crash from access violation, in most cases it is assetion fail. Engine code have assertion check points which checks if conditions are as code expects to be, if it’s not it crashes the engine. It might sound stupid thing to do, but point is by expecting specific state is a lot better to crash the enigne then later have unexpected crash due ot instability cause by condition that was not expected. IF asset check fails it print out in log failed condition (condition like in if statement, that was false) and path to code file and linme numebr, in most cases it is readable but sometimes you will need look in file, some assets have even direct message what happened. Yo can read about it here:

Trust me it will save a lot of time tile then trying to guess, at minimum look in to logs, if logs are cut then that means you got memory access violation most likely due ot null or invalid pointer or some data corruption, then use VS debugger.

That all i can say from what you gave, you forcing me to guess what is you setup and what you trying to actually do you need to provide more information and see why you actually get a crash, look in to logs

Hello ,

First of all thanks for such quick and detailed answer(Up vote for that ).

Now about the set up part, it is exactly as you said. I have AStaticmeshActor which will spawned on
viewport with static mesh inside of it.

When i import the model in ue4, my plugin will create hierarchy of actors in outliner (main parent-parent-child-so on…).
Now Main parent and parent are empty actors while child will be actor with static mesh attached to it. For all i will create assets in
content browser. For giving some additional functionality to main parent and parent i have my own actor class call OwnActor.
For this i will use ActorFactory and ImporterFactory structure of UE4.

UCLASS()
class AOwnActor : public AActor
{
	GENERATED_BODY()

.
.
.
.
.
.
}

After import process is done all the things are created as asset in cotent browser and here if i try to open the Main parent UE4 crashes, as you said UE4
is expecting Uworld to be attached with AActor and getting crashed

Assertion failed: ActorInfo.SharedWorld [File:D:\Build\++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\AssetSelection.cpp] [Line: 136] 

and the code on that line is as follows

if( ActorInfo.bAllSelectedActorsBelongToSameWorld )
{
		if ( !ActorInfo.SharedWorld )
		{
			ActorInfo.SharedWorld = CurrentActor->();
			check(ActorInfo.SharedWorld); (**CRASH**)
		}
		else
		{
		       if( ActorInfo.SharedWorld != CurrentActor->() )
			{
					ActorInfo.bAllSelectedActorsBelongToCurrentLevel = false;
					ActorInfo.SharedWorld = NULL;
			}
		}
}

So what can we do to avoid this crash ? or do i need to change the complete structure which will not be possible freckly speaking ?

that means CurrentActor->() return null which means either actor is not attach to the world, or is not fully initiated. It happens in asset selection code, it geter info about selected actors probably for action on asset to related actors. For some reason selected actor don’t have UWorld instance attached.

So if understand correctly you got asset UObject (not AActor) which when you drop it on the level it creates series actors based on data in the asset? You need to review how you do it since it seems issue is in there. Also this crash happens when you select asset?

It is AActor i.e. the asset is AActor not UObject.

The crash happens when i double click this actor asset.

Then thats the issue, you should use use UObject, AActor needs UWorld instance to live and function properly, what you doing is literally asking for crashes, it explain why you get null pointer in some random () in engine code. Your asset should contain only data of actor structure and UActorFactory should reconstruct it to actor. Even Blueprints are not actors, they just have info the class which generates UClass from which you spawn AActor.

If all you want is prefabs, there already plugin that does that called prefabricator:

https://prefabricator.io/