Yes. But there's a lot more to adding a new controller than just creating the object... There's a bunch of registration and management happening behind the scenes as well as many related classes.
The default, single controller behaviour has suited us fine for now so I don't know a lot about how multiple controllers would be done, but I know it should likely be in AGameMode. Look at AGameMode::Login and AGameMode::InitNewPlayer in particular and where those are being called. It looks like UGameInstance::CreateLocalPlayer calls those as needed and would probably be your best starting point.
-Camille
Announcement
Collapse
No announcement yet.
How do you instantiate things in Unreal Engine?
Collapse
X
-
jimmyt1988 repliedWhat if you want 4 local players.. I need 4 Player Controllers... Don't I?... Each with their own Input Components...
Leave a comment:
-
cmartel repliedCast of Class /Script/TemplatePlatformer.APlayerController to Level failed
For starters, you shouldn't have to manually create a player controller, the level startup takes care of that for you.
Leave a comment:
-
jimmyt1988 repliedThanks, I hadn't realised it was based off of an actor too. Nice one.
Leave a comment:
-
illYay repliedThis is an article about spawning actors:
https://docs.unrealengine.com/latest...ing/index.html
I don't have the code in front of me but spawning components and other UObjects uses ConstructObject. I think the Unreal Tournament source code has a lot of examples of doing this. One thing to keep in mind with spawning components is you still have to register the component manually I think after it's spawned, otherwise you won't see the static mesh in the world or whatever it is you spawned.
Leave a comment:
-
jimmyt1988 started a topic How do you instantiate things in Unreal Engine?How do you instantiate things in Unreal Engine?
I require a second PlayerController...
I realised you cannot do
Code:APlayerController* controller = new APlayerController();
I've tried this but it throws an error:
Code:NewObject<APlayerController>(APlayerController::StaticClass());
Code:ConstructObject<APlayerController>(APlayerController::StaticClass());
Code:Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.6\Engine\Source\Runtime\CoreUObject\Private\Templates\Casts.cpp] [Line: 11] Cast of Class /Script/TemplatePlatformer.APlayerController to Level failed UE4Editor.exe has triggered a breakpoint. UE4Editor.exe has triggered a breakpoint.
Last edited by jimmyt1988; 01-13-2015, 09:31 PM.Tags: None
Leave a comment: