It works flawlessly while all the components in the actor being copied are generated form code. Once I add a component through the editor, I start getting crashes every time SpawnActor gets called. I get no log, but through Visual Studio debugger I get a “Access violation writing location” exception at mallocTBB.cpp line 93.
Am I missing something, or is there perhaps a betetr way to copy objects?
I did a bit of testing on a fresh project. It turns out all I have to do to reproduce the crash is to call CreateDefaultSubobject from the actor constructor (does not matter which component I create), then attach another component form the editor and call SpawnActor with Parameters.Template = this; somewhere in code.
Have I smashed my head against a bug, or am I doing something wrong?
I’ve been trying to solve this problem for days, I think I found the solution.
I had a C++ component added to my blueprint. I realised that attaching this component to any object, through C++ or BP, will crash the game. Standard null pointer crash, I just didn’t realise where it was coming from.
Check all your code, components, classes etc., see if you have any null pointers. Remove them or fix them, and it should work perfectly.