Instantiating object crashes everything

You shouldn’t be using “new” to create AActors, nor directly calling the default constructor. “new” is rarely used within UE4 projects because it bypasses the garbage collection system and a lot of the built-in UE4 niceties - and in my opinion should never be used to create AActors or UObjects. It’s not impossible, but you should be very conscious of where and why you are using “new” rather than the “UE4 way”, and what you need to do to ensure you don’t cause other conflicts within your program, especially regarding memory leaks.

AActors are created with the templated method UWorld::Spawn<classname> and UObjects are created with the templated method NewObject<classname>.

In your example you want to do something like this:

UWorld* LocalWorld =  GetWorld();

if (LocalWorld) {
    AExploreNodes* n = LocalWorld->SpawnActor<AExploreNodes>();

}

There are a number of spawning parameters you can pass using a FActorSpawnParameters argument, as well as a few different versions of this method that allow easy setting of position and orientation within the game world.

See:

Also, the documentation here is a bit out of date, but can get you started:

NewNamedObject and ConstructObject have been deprecated in favor of exclusively using NewObject.

As to what’s causing your crash, it’s difficult to know without seeing the text of your errors. In general, it could be because the class isn’t included in your header (although that would likely prevent compilation) or because the AActor is otherwise malformed. If you implement the SpawnActor method and are still encountering problems please provide more information as to what’s happening and the text of any error messages generated within the editor, the crash report utility, and/or within the game log.

I added a c++ class based on an Actor to my project. On an event I try to create an instance using default contructor but crashes.

It for some reason won’t allow me to use:

AExploreNodes n = new AExploreNodes();

so instead I use:

AExploreNodes *n = new AExploreNodes();

But it crashes the game and editor.

This tutorial showed how to ‘spawn’ actors: https://docs.unrealengine.com/latest/INT/Programming/Tutorials/FirstPersonShooter/3/2/index.html