This saves the newly spawned actor in a variable called spawnedActor. You don’t have to save the actor into a variable if you don’t think you’ll need to access it later on. Hope this helps!
I simulated what you’re trying to do within my own project and I don’t seem to get a crash.
I’m guessing that ‘line’ and ‘gameField’ are TArrays. Did you declare those arrays in the header (TicTacToe5x5GameMode.h). If you didn’t, try doing that as declaring an array within your spawning method exclusively won’t stick around after the method executes. At least, that’s what I think. Also try to comment out lines to see where the crash occurs.
the code looks fine so there is a problem outside that snippet, like everybody says its either the gameField not being initialized or the problem could be within the Aunit class?
The pre-requisite is that your actor is replicated. Please note that actors deriving from AActor are not replicated by default, so you need to add in their constructor:
bReplicates = true;
or within the editor you should flag your actor as “Replicates”. It is one of the properties in the details panel.
If you want to create your actor completely within C++, and you have only the StaticMesh and the Material in the Editor (this was my case), you can create it like this:
Also in this case the pre-requisite is that your actor is replicated. Same case for case 1.
If your actor is invisible client side, means you didn’t replicate it, or you didn’t set the position properly. Please note the SetWorldLocation call despite the fact you are already giving the location in the spawnactor command. For me it works only if I call explicitely SetWorldLocation