Accessing variable in one Blueprint class from my PlayerController class

Hello everybody, thanks for taking the time to read my question.

I’ve done a lot of reading, testing and tweaking of my own Blueprint code to try and get this working but I just can’t seem to find the fix.

I am currently inside a project that is using the mouse cursor as its main source of input from the player. I have an action mapping set up named “Select” which is bound to the Left Mouse Button.

I have a Blueprint Class called ClickMe which currently holds a variable inside called bHighlightingActor (it is a bool). When the mouse is hovered over the object, the bool is set to true, and when it’s no longer hovering it is set back to false.

Inside the PlayerController I am attempting to access the value of this bool from inside the ClickMe class.

For starters, bHighlightingActor would probably be best set up inside of PlayerController as I am likely to need it for a multitude of actors inside my project. Regardless of this, however, how best do I go about accessing and using the value of variables within other classes?

I have looked at creating an object variable that references the Blueprint Classes in question but it does not seem to be helping.

Thanks for your help, the relevant Blueprints are attached.

Hey skus,

I commend your effort. Some preliminary questions. Is this Actor you’re hovering within the Level? If so, how are you accessing this Actor and placing the reference in the variable you’re attempting to retrieve Highlight State from? Is this the only Actor that you can hover over? Have you considered using Get Hit Result Under Cursor by ChannelBreak Result, then casting Hit Actor to the Actor you’re attempting to access?

Otherwise, good work I must say!

Peace

To answer your questions:

Yes the actor is within the level. It’s simply a cube I’m using to test all the different kind of RTS functionality I might want on a certain type of unit or other selectable actor within my levels. I’m hoping it turns into my base actor class for units, actually, but that’s not a concern at this point.

The reference is being made by creating an object variable inside the PlayerController class and exposing the variable. As far as I’m aware this is also known as Blueprint Comms, I followed this link to get that result, The part I’m missing however is selecting the instance to use - I have no idea where that dropdown box is:

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintComms/index.html

There shall be multiple actors you can hover over / ‘select’ in the future, this is just laying down a framework for the rest of the project and also testing out some stuff.

As I was writing the question I thought about using Get Hit Result Under Cursor by Channel (I previously used this to spawn a particle at the mouse’s location when clicking on the actor).

My follow up question is, what is the need for setting up Left Mouse Button as an action map if I can just use the Get Hit Result function?

And thank you! It’s been fun hunting for the solution, but my brain hurts a little now so I need to seek help!

Get Hit Result Under Cursor by Channel updates constantly. The use of Left Mouse Button would be to initiate the check of the results on Click.

So after that, I can firmly say what you need to do in this situation is remove any functionality from the RTS Unit not directly related to the Unit. This would include updating the Player Controller current mouse Icon. What I would suggest is leaving the Highlighting Actor bool variable. Then instead of the Unit, have the Player Controller set that to true when that Unit is hovered. Now the Unit will check that internal variable and make changes accordingly such as changing its material to Highlight. Then the Player Controller can grab the Unit’s name and use that for another purpose. Just to give you an idea of the work flow.

Another issue, how you’re accessing the Blueprint Actor is incorrect. What you need to do is grab Unit from the Get Hit Result as we talked about above. Then casting this to Unit Class, and accessing it directly from the cast ( In Example its As Character , your would be As Unit ). This will guarantee you’re highlighting the Unit. ( Note: I would use a Branch to check Return Value bool on Get Hit Result to ensure something is under it at time of Click )

If you’re not in the Controller, you can always use Get All Actors of Class then Loop and check as necessary. I would use this in the HUD class to draw all the Units name above them. I’ve put an example below for you.

I dare not let you think I’ve just read this and ignored your awesome reply. I have to say it’s not making much sense to me right now, but I am really tired. Gonna’ hit the hay and try again tomorrow. Maybe there will also be some more replies when I wake up, fingers crossed. :slight_smile:

Thanks again, you’re being a lot of help already. Have a good night.

I still can’t quite figure out how best to do this.

Or even to get it to work at all, actually.

The main issue is - now that I’ve got the utility happening inside the controller - accessing the bool (bIsHighlighting) from the ClickMe actor.

My attempt there was to check if the actor I hit is the same as the actor I’m looking for (in this case, an instance of the ClickMe actor) but it of course doesn’t like my use of the Highlighting Actor bool elsewhere in the graph.

So in short I guess I’m going wrong when trying to access the variables from the ClickMe class. Still looking for help! Thanks guys.

Sorry, had to take a trip this weekend. So in order to access the variable in the class you pull from the Break Hit results, you need to have the variable editable in the ClickMe class. Also the images in the post don’t seem to work. D:

I’m currently looking to getting your suggestion implemented - but I’ve had to remake all the old input stuff I had working as I’m on another computer so I’m basically starting again and getting some odd hiccups along the way.

I’ve actually posted a question about it on here, if you feel extra helpful today SilentX` :wink:

Thanks for your patience

Hey skus,

Check out what Steve Allison made, much more efficient.

Peace

Hey skus,

Another route you could consider doing is making a custom actor blueprint that all of your placed actors will be based on. In that blueprint, have the begin/end cursor over events that call a custom event in your custom player controller. This custom event handles your cursor change, etc. Here’s an example of what that would look like:

MyActor:

MyController:

Your custom actor blueprint could also have an OnClicked event that calls another custom event for in your player controller if you want to mimic that actor being “selected”.

If you have any questions about this setup, please let me know.

Cheers,

-Steve