At the same time, it also sets itself inside the “Nox Player Controller Reference” of the blueprint character.
The blueprint character is a child of a base character class that contains this variable. Inside the base class, the variable is set to instance editable so that child actors can edit the variable (i think…?)
So TLDR: I have a base actor that contains a custom player controller variable, I spawn an instanced child actor through the player controller and set this variable through the player controller.
BUT THE VARIABLE IS NULL WHEN I TRY TO USE IT THROUGH THE CHILD ACTOR.
Are you sure that you’re possessing the actor? By your logic you are setting the property and possessing the same actor so the value should be set. My first thought would be to validate that the output from GetActorOfClass is giving you a value in the first place.
Also, is it a single player game? if so, can you not just GetPlayerController() from your character class and cast it to your custom controller.
This is kind of a wrong approach. Firstly, you can set a pawn on a level to be automatically possessed by the player controller by setting this option in the details panel:
Just make sure that you have selected your player controller class in your game mode
Other than that, pawns have an event called Possessed that will get triggered when a controller possesses them. The event also has a reference to the possessing controller, so you can use that to populate your controller variable:
Also all of that is valid for single player games only, or for server only functionality
Also, I just realized, I’m not even able to set the variable through base class… So I don’t think it’s an issue with the player controller… I tried creating a float variable in base class and setting it too through the base class’ begin play and it still shows the float variable as 0 in the child actor. Wut.
Yes but I don’t want the pawn being possessed automatically. The pawn possession is sucessful every time. I’m just unable to set variables inside the pawn. I’ll try using a BPI but I feel it’s a bit of an overkill for setting a simple variable, not sure if it’ll even work
The thing is a player controller only exists on the server and the owning client, the other clients don’t know about other players’ player controllers, so maybe that’s where your issue is. If you have logic in your pawn for example that reads the value of the player controller variable, but that logic is not behind an IsLocallyControlled check, or a variable validity check, then every client will try to run that logic, even if it’s not “their” pawn
If you want to have different players possessing different pawns on the level, perhaps you should do that in the game mode, using
Because a player controller is spawned automatically when the game starts, and you are doing your logic on begin play of a player controller, I don’t see how you don’t want to automatically possess a pawn, unless I’m missing something
FIXED IT. AND I KNEW IT WAS SOMETHING VERY STUPID.
Basically I was having the player controller set a variable inside an actor and at the same time, I was having the actor call that variable on begin play.
Actor kept trying to call the variable before it got set BECAUSE THIS GODFORSAKEN NODE IS SLOW. It even says it’s a slow operation in its context menu.
So a simple delay node on the begin play of the child actor fixed everything.
Player controller is created before actors are spawned in the level. Therefore you are trying to get an actor that is not there yet.
You can set yourself up for success by making sure to use print logs connected to is valid checks pretty much any time you are attemtping to communicate between one actor/class and another. Create an error message that describes who/where/when/what/why, that way when there is some problem (you cant avoid them) you wont have to use much brain juices to find the problem spot and remember how things work.
It seems tedious but it beats lengthy debugging via a lot of guessing.
Another thing that may be of interest, be aware that you can use a “get player controller” node from anywhere which will find the base class that unreal is always spawning by default.
If you want to get at your instance of the player controller, you can cast to it or communicate via an interface.
Using the interface will allow you to communicate without having to actually reference the instance of the player controller directly.
Get Actor of Class is relatively slow (it iterates through the entire actor list, which can be slow) but it’s not delayed.
Your issue is that you are searching for something before it exists.
If you’re using a Delay node to get around something not working, it’s almost always an indication that something is implemented incorrectly. Likewise, if you use Get Actor Of Class for anything you’re probably doing something at the very least in a poor fashion, if not incorrectly. That’s not to say that these nodes don’t occasionally have use, but a Delay to get around synchronization problems is almost always an error, and not knowing what actor you want to do something with before hand, is almost always an error, as well. (especially since Get Actor Of Class will just return the first actor of that type in a level)
So, without really knowing what you’re actually trying to achieve here overall… what i see, is that you already have a Pawn in the game world, somehow or other. You want a player to login and possess that pawn.
So, over on the server side, in the game mode, when a playercontroller logs in, you want to have it possess the existing Pawn. Since it is usually up to the GameMode to spawn the pawns, the GameMode should already have knowledge of which pawns exist, so all it has to do is call AIController::Possess with the given Pawn. If your GameMode doesn’t already know what Pawn to possess, then it probably should have already queried the world to find all the pawns, before you got to this point.
Then, in your Pawn’s OnPossessed event, you can cache a reference to the Controller.