UE 4.22.3 | Listen Server
I want to spawn an Actor by the Server like this:
Then I want to get the return value for the client. I tried it in several other ways, but the only way it really made sense in my head was like this:
But the variable “SpawnedAbility” always returns NULL.
Should I approach this entirely different or is there no way, to spawn an Actor by the Server and give a reference to the client properly?
After trying out many things and informing myself as much as I could, I am almost certain, there is no way to do it as simple, as I did in this example.
It makes sense, that it would not be possible, because the *server *spawns and replicates the object and has authority over it. I guess I made a “beginners mistake” here, thinking this might be possible. Which also leads me to a different code design.
For example, if you want the player to “cast” a fireball that hits a target, the fireball as an object itself would *NOT *be spawned at all, until you are sure for it to be fired. Code like making the character “cast” and wait a specific time until the fireball is fired, should be implemented entirely within another BP, like the character BP and when the “casting” is done, it would spawn the fireball, feeding it info like the target for the projectile homing system. Then the fireball would spawn, immediately home towards its target and on hit run the code it is supposed to. (Like applying damage to the hit target).
This way if you would want to cancel the casting, you would do so from within the character BP and just never spawn the fireball and additionally you will not have any issues visualizing the abilities cast and slot in the client’s UI.
Someone correct me if I am wrong here, but I think my approach does make sense, when it comes to a multiplayer game. And to be clear: There is a post that claims there is a way for this to be possible, but seemingly only in a workaround kind of way.
This tutorial is **NOT **meant for multiplayer, though if you want to know more about how you might want to set up an ability class, to create ability types from that class and then single abilities from that, I recommend looking into this tutorial series. I think he does a good job at building up a parent class for an ability system.