Advertisement

PlayerController Question

Started by July 01, 2017 07:29 PM
1 comment, last by Scouting Ninja 7 years, 5 months ago

I using this tutorial to make my game

if want to use the playerController like this toturial

My question i only have to port my input from character class to my playercontroller

 

Hello

First this isn't a player controller question, it's sending a message between two classes.

The way I will show you here is a hundred times easier than what most tutorials teach.

 

First you need to understand the idea: You have two classes/ blueprints that one of them needs to receive a message from the other.

The problem is that the one class has no idea where the other class is or how many there is.

Edit:

Format wasn't planned, works for a tutorial.

Vid added to show real time effect.

 

Here is the end scene:

It is a lot of the same class/ blueprint called "Target". There is two lights. We want the first light to to get the color of the first target. We ant the second light to get the color of the target named Bob.

 

0_EndResult.thumb.png.0f12e42410384cf5c6e965126497a659.png

Also to get the color of a material in Unreal it's easier if we set the material color to a parameter and call it "ColorOfMaterial".

 

1_MaterialSetup.png.4648024ec273a199834fd87237ad31f4.png

Now with this done we go into the Blueprint of the light.

We add a "Get all actors of class" function to our update event.

The actor we are looking for is called "Target" as you can see in the first image.

 

2_FirstFindTheTarget.png.5a3a4205b3a6daa9a3a6dca7ded49f63.png

Now because there can be more than one blueprint in the level of the same type, Unreal will give us a list of objects of the type.

Now because we only want the set the light to the color of the first object, we tell unreal to take the 0 object on the list. Computers count 0-1-2-3...

Once we have the 0 object on the list, we want it's material so we can get the color stored in the material; first we must get the material.

 

3_GetTheVariable.png.2758df3a4604e9d4928463de1e698dd4.png

Now that we have the first object in the scene, grabbed it's material we can get the color.

Color is stored as a vector value (Red,Green,Blue,Alpha).

Because all color in the Unreal uses the same color vector we can just plug the color from the material into the color of the light.

 

4_SetLight.thumb.png.2970bfde78afff3956603bcacb9d2ce8.png

 

OK, We are done.

The color of the light will now be the same as the color of the material from the other blueprint.

 

Setting the second light is as easy as using a branch/ if to check for the name:

We use a for loop to check each object in the list of "Target".

We get the object name and compare it to the name we want, I named that target "Bob".

We set the color of the second light to the color of "Bob".

 

4_SetLight.thumb.png.2970bfde78afff3956603bcacb9d2ce8.png

 

Doing it this way is very easy, yet it can be slow in large scenes.

Once you understand all of this you can search how to make a "get" function.

You could also ask here how to make a "get" function, you need to learn this first.

RealTime.avi

This topic is closed to new replies.

Advertisement