Engine crashes when using NewObject<>()

This is the correct way but I’m fairly certain multiplayer is what’s causing the problems. I’ve only worked a bit with it but I think you may be having an issue with replicating the tarray and replicating what’s inside it. Can you try having an A Weapon* startweappn defined in your .h, replicate that in getlifetimerep function, assign that to your first weapon spawned and see if that will print its name instead of the inventory for now?
Also, in your A Weapon class constructor make sure you set bReplicates = true

I don’t think it’s a networking issue:

This makes the engine crash

I tried with Inventory.AddUnique(Initial) and it works. But as long as I set Role == ROLE_Authority… it doesn’t work any longer

I’m that case Inventory[0] doesn’t exist,your want to do Inventory.Add(Initial). Otherwise I’m out of ideas, I’ve got actors spawning the exact same way in my current project with the only difference being it isn’t multiplayer and I’ve had no issues so far.

So yeah, what I believe is happening is…

  1. Server spawns weapon, adds it to the TArray<>
  2. TArray<> is replicated, the client now knows something is in it
  3. Client accesses the item in the TArray<>, but the actual item in it isnt replicated, so the client is accessing null value-> Crash

I think all you need to do is make the AWeapon constructor set bReplicates/bIsReplicated (can’t remember the name but its something like that) to true inside the constructor and you should be good to go I believe.

Yeah, it works.

So the Inventory was replicating, but the Weapon wasn’t.
Nice twist.

Thanks!

Glad I could help!