I’m using ue 4.21.2. I want to spawn an actor in AMyPlayerController constructor, but it immediately crashes the editor (won’t even load the project) even though the solution compiles with no error in visual studio.
// some stuff
m_some_actor = GetWorld()->SpawnActor<ASomeActor>();
//some more stuff
ASomeActor * m_some_actor;
for reference, the specific SpawnActor overload its using is in World.h. There shouldn’t really be any problems regarding incorrect usage of the method signature
Also confused as to why the editor is crashing on clicking “Compile” to begin with, I can’t even attempt to “play” it. The solution builds with no error in visual studio. It’s one thing if the compilation were to fail and an error is reported in the editor, but for the entire application to crash simply from attempting a compile?
Compiling without errors is not something you can rely on ever, compilers cant understand your code. I have been away from unreal engine for a long time but i do remember that using GetWorld in a constructor is a bad idea, even worse in “editor” mode. First thing i would check is that you actually do get a result from it.
If my solution compiles without error, I expect the editor to at least open. But this is based on my underlying assumption that the editor isn’t trying to run my game unless I actually hit play, which seems to not be the case.
Why exactly is using GetWorld in a constructor a bad idea?