I’m trying to cast to an actor class so I can access my variables. However, when I try to cast to the actor I get an error and it doesn’t load the values of the variables. I have my actor class placed in my level. Here is how I cast.
First thing I would do is execute a “Print String” between “Get All Actors of Class” and “Cast To Variables”. Drag off “Out Actors” and add a “Length” node to get the number of elements in this array, then feed it into the “Print String”. This will tell you if this node is actually returning any actors. My guess is it’s not finding any for some reason.
Another error check you could add for good measure is dragging off the “Get” node’s return value and running an “Is Valid?” node. Then, only Cast To Variables if the Is Valid node returns true, this way you won’t try to cast if for some reason the Get All Actors Of Class didn’t work.
Your naming conventions are a bit confusing. In this setup, you have a “Variables” class, a “Variables” actor and a “Variables” variable. I would suggest naming them slightly different names to make it more readable.
What is the error message? That’s essential to see what’s going wrong.
Hi Chumble,
I did your first method and the print string returned with 1. I did your second method and it came out valid. Not sure what’s going on here, it should work.
Looks like all of these errors are occurring in a different blueprint. The Cast you posted seems to be working fine. I think we’d need to see the event graphs in Popcorn and Pizza.
Hey!
“Get all actors of class” returns instances of classes you’re requested for, not pure actors so you should not cast it again - it will fail. Just set variable using instance you got from “Get 0” node and it will work correctly.
Currently your “Cast” node going into Fail state and your variable is set to empty. When you’re trying to access members of “empty” Variables you get this “None” errors
Here is the event graph for Popcorn:
Here is the event graph for Pizza (Pretty much the same thing):
I haven’t changed anything in these event graphs yet because I wanted to fix this error first.
Ok, so even that first branch isn’t working.
I’m having trouble making sense of this. In your first posted event graph you have
- Get each actor of the class “Variables”
- Get index 0 of the found actors
- Cast the found actor to actor “Variables”
- Set local variable called “Variables” to be the actor reference to “Variables”.
I’m not sure what you’re trying to accomplish here. It LOOKS like you’re using an actor class to hold “global” variables. This might be better achieved within a Game Instance class instead.
Where is the event graph for your first post? It looks like you’re assigning the return from your Cast node to a local variable. If this is the case, Popcorn and Pizza will never get their version of “Variables” set and you’ll be flooded with errors.
I fixed the error. However, I am really confused right now, I feel like this should be working. I have 2 widgets, “Hamburger” and “Popcorn”, when I play the game, they are both added to a wrap box. Each one is setup as follows:
As you can see both widgets have an image, a button which covers the image, a border which turns green when the button is hovered and a checkmark that is hidden, but is visible when the button is pressed. As I said, they are both added to a wrap box. Say I click on “Popcorn” in-game, the checkmark will then be visible. Then say I click hamburger, the checkmark for “Hamburger” will then be visible. I don’t want both the “Hamburger” and “Popcorn” checkmarks to be on at the same time, so when I click on the “Hamburger” widget I want the “Popcorn” checkmark to be hidden again. This is what I thought I had to do.
My eyes! :eek:
You need to re-work this, it’s baaad code. Sorry I don’t have time to write a more complete answer but this should point you in the right direction:
Create a ‘product’ enum with Fries/Hamburger/Ice cream etc.
Create a widget with a ‘product’ variable
Create a custom event called ‘OnProductClicked’ with a ‘product’ input
When the widget is clicked, fire the OnProductClicked with the ‘product’ of the widget
Bind the event wherever you want to handle it