Download

Spawning as character from widget / start menu

I’ve been trying to create a start menu for a game I’m creating. I want to be able to choose between different playable dinosaurs. Currently, I can select in my GameModeBase blueprint to select either Playable_Entity_Velociraptor or Playable_Entity_Utahraptor and both spawn me in properly, but now I wish to be able to select on the start screen which to spawn in as. I have the following Widget blueprint set up, and I’m not really sure why it isn’t working. I spawn in as a noclipping camera.

Does anyone know how to accomplish this?

I tried following this forum post as well, but it didn’t work either.

https://answers.unrealengine.com/questions/387475/spawn-actor-from-widget-in-another-level.html

I cant see any attached image so ill try to describe setup… (if this is single player)

Create variable “dinosaur character - class” and assign different classes to different buttons…
On clicked button, get owning player → cast to your player controller → set pawn to spawn (you must create also this variable “pawn to spawn” in your pkayer controller)
In PC when you decide to respawn, use spawn actor class and possess it with your player controller…

Let me know if its working i have tested only multiplayer respawn systems so maybe there is easier way how to do this.

Hello, and thanks for replying to my post!

I created a variable named Dinosaur Character in my widget blueprint of type Actor - Class. This was the type I needed to be able to assign it to be either of my two character blueprints, which represent my two dinosaurs.

When each button is clicked, I assign Dinosaur Character to be one of these two blueprints. Then I get owning player, cast it to my player controller, and set a variable I created named Pawn to Spawn from a blueprint I created named PlayerController of type Player Controller. Edit2: I just checked this, and my cast is failing here in the widget blueprint.

I have one character blueprint named Root_Playable that has all of my control inputs. It has two children, one of which is named Playable_Entity_Velociraptor, and the other Playable_Entity_Utahraptor. Typically I select which one is my default pawn class in my GameModeBase blueprint and it works alright. How would i go about spawning as what I set ‘Pawn to Spawn’ to be in my player controller BP? I can’t seem to access that variable from Root_Playable.

Edit: I found out how to access Pawn to Spawn, but my cast fails. Here is the setup I have (3rd posted picture). Currently, I am attempting to spawn when I press a key on my keyboard I designated as ‘debug.’ If this works, I’ll set it to automatically do this on the Event BeginPlay.

Blueprint.PNG

Blueprint2.PNG

21551af46dfccc3362e29f5bf6628be526c09156.png

It looks good, but:
cast to “player controller” is bad cast… you must cast it to “your player controller” which you created (if you dont have created PC, then create one and call it for example dinosaur_player_controller) … and that “set → pawn to spawn” node has target pin, there you must connect pin from “cast to your PC”

I went ahead and renamed my PlayerController blueprint to Dinosaur_Player_Controller. I did have to swap out the block ‘Cast to PlayerController’ with ‘Cast to Dinosaur_Player_Controller.’ The cast is still failing.

Also, when I try to attach the ReturnValue pin to the InPawn pin of the Possess block, it gives me an error ‘Actor Reference not compatible with Pawn Reference.’ If I disconnect the actor pin and select Playable_Entity_Velociraptor or Playable_Entity_Utahraptor from the dropdown menu on the SpawnActor block, however, it lets me connect this pin.

8ae87100551b56923d02cc5cff69fcfaab3a3a1f.png

98910c0fc7167c0a2b2b632840f75c4a9db752bd.png

so, in world level settings, you have set gamemode and that have sub-classes like spectator, player/game state and player controller → assign to your levels dinosaur player controller as default controller for these levels… after this cast probably won’t fail anymore…
Show me your spawn actor bp then, when i connect my pin of character class, i automatically get character output - its working for me…

I set Player Controller Class to be Dinosaur_Player_Controller in the world settings for my starting screen map. Under Tropical_Island_1, which is the map I spawn on, I have GameMode Override set to ‘None.’ My DinoSelect widget blueprint no longer prints a failed cast message to my screen when I play, and I spawn on the map as a camera that can move around.

When I press my ‘debug’ keybind, I’d want it to spawn me as whichever button I pressed on the select screen. When I press it, however, the cast in my character blueprint is failing as I can see ‘Trying to spawn’ followed up by ‘Cast failed’ printed to my screen.

I have now attached my SpawnActor blueprint. It’s located in Root_Playable, which is my character blueprint. I sort of guessed the object input to my Cast to Dinosaur_Player_Controller block, so maybe that’s the issue.

Also, I copied the SpawnActor block and pasted it below on the bottom right. Here, it allows me to connect the InPawn input to Possess to the Return Value of SpawnActor, but it does not when I use Pawn to Spawn as the input to this block.

Character BP.PNG

WorldSettings.PNG.jpg

BeginFromMainMenu.PNG

mesh -> get owner - this is definitely bad, replace it with “get player controller” node
into possess node, into target pin connect “as dinosaur player controller” pin from cast node

How you created dinosaur classes? i think they are based on character class… but then which class is “pawn to spawn” class? it should be “character - class”, not actor class…

Oh! You’re right. My Playable_Entity_Utahraptor and Playable_Entity_Velociraptor blueprints are character classes, and I did define Pawn to Spawn in Dinosaur_Player_Controller (Player Controller BP) and Dinosaur Character in DinoSelect (widget BP) variables as Actor - Class. I went ahead and changed them. I no longer fail any casts and when I press my debug key, it now gives me a ‘Spawned!’ message on the screen. I was also now able to connect the Return Value to the InPawn pin on the Possess block. I do not, however, seem to spawn or possess the dinosaur. When I reconfigure the wiring to the second image, I spawn as a velociraptor since that’s what I selected in my dropdown menu without the Pawn to Spawn as my input pin.

I also attached where I define Pawn to Spawn, along with a picture of my new DinoSelect screen that seems to work without failing its cast.

Character BP.PNG

Character BP 2.PNG

Dino_Player_Controller.PNG

862b49260ae5d7e4e078b9aecac99382a243876c.png

hmm so if thats not working (setup 1) then plug “get player controller” into possess node, instead of “as…” from cast node

Opening a new level destroys every Class except GameInstance, and so your Class to Spawn variable is also being cleaned up which is why nothing is spawning in picture #1.

So the solution is probably going to be creating a custom Game Instance and storing a Class To Spawn variable.

Oh yes, this is right, its working for me because im using loadgame in my player controller…
so for predatoria: instead of playing with player controller, create your game instance class and use nodes “get game instance” → “cast to your game instance”, and there you can set/get values…

Hello all,

Sorry being a bit late, had to afk for a bit.

I went ahead and swapped out my Pawn to Spawn variable located in a Player Controller class blueprint with one named DinoToPlayAs, located in a Game Instance class blueprint.

I am now, however getting a cast failure on my DinoSelect Widget blueprint. Here’s my current setup:

G_Instance.PNG

DinoSelect.PNG

c23e42ecab965387be8490a414392a7b31fe3e0f.png

In project settings, probably somewhere in level/maps you must set that game instance as default game instance

I just got it working!

There is a setting you need to set under your project settings tab for the game instance. It must be set to match the name of the Game Instance blueprint my variable is under. Here’s a screenshot: For anyone later reading this post who wants to setup something similar where a widget blueprint spawns a character on a map, my previous post contains the three parts of the necessary blueprints that must work together to allow this to happen, along with ensuring you set the Game Instance project setting correctly.

Set Game Instance.PNG.jpg

And it works!!!

Thank you both so much for helping me with this. Though I have a bit of background in programming, a lot of these casting / object oriented programming aspects are quite foreign to me.

Also, is there a way I can mark this thread as resolved? Or does that need to be done by a moderator. I’m quite new here.