Change actors variables before possessing or spawning them?

You can’t set dynamic variables to actor before it spawn, because Actors are special objects, that only exists when spawned in world (map). You can change variables in actor class before spawn, but it will work with all other actors of this class.

But you can easy change variables right before actor spawn, before it will ‘work’ in world.

  • Set variable from Return Value (this is Spawn AI but it works same way with spawning other Actor from class)
  • cast this variable to your actor and set variable this actor have - in this example this is Health and it sets to 80.

https://i.imgur.com/DAQLvgB.png?1

If you have this actor as variable, you can do any changes later - before poses or anytime you need.

And here how it works with simple SpawnActor form Class (it not need cast):

https://i.imgur.com/2GWTW0d.png?1

As you can see, here you can set variables directly in SpawnActor From Class if class is selected and blueprint is precompiled - like a bullets, magazines etc in this example (they are variables in Crowder class).

Auto spawning of pawns is managed by game mode, you can override it’s default behavior in there. You have option in game mode to “Spawn Player as Spectator” so player will start as spectators, you make player pick the loadout and other stuff and call RestartPlayer when you want pawn to spawn.

you mean, something like a lobby before ‘game’ start and player spawn and different variables for different players - like one with AKM, other with pistol?

Is it possible to modify the variables of an actor from blueprints before you possess them? Or even from before spawning said actor? I’ve currently got a UI which is set up and works for changing weapons while the actor has spawned however I want to set up a system where I can change the loadout before the actor has spawned. Casting to the player doesnt seem to work when there is no player there.

So how could i apply that logic to this, baring in mind i’m trying to do this from a widget? What I have works now while the pawn has spawned, how would it work when the pawn hasnt?

If they should be a players, you can use this @anonymous_user_f5a50610 method with spawning player as spectator. In any other case, if you want to set object variables on spawn, use this I posted - you can set variables in SpawnActorFromClass or/and inside spawned actor just before spawn.

With lobby you can also create array of objects, every player will be one of object in this array. In this object you can set variables for future spawned player and his class. Variables like a weapon selected etc. Then, on real spawn, you can set variables on actor from this object. This is similar to spectator player with some pros and cons.

Best for you would be look on youtube for lobby tutorials, there a lot and you have to do many other things for lobby like this, for example check that player can get weapon or is already selected by other player.

https://www.youtube.com/results?search_query=unreal+engine+lobby+system

and here 1st from this list, from Epic Blueprint Multiplayer: Lobby Game Mode | 15 | v4.11 Tutorial Series | Unreal Engine - YouTube

Anyway, this is answer to your question and would be best - close it and if you have questions about lobby system post another question - you will have more answers.

Yes exactly that, I thought it would be simply but every method I try fails.

For anyone wondering how to add the pawn variables to SpawnActor node, check the last comment here:

1 Like