Download

Cast To Object Referance Issues

I’m having issues when it comes to referencing a variable from one blueprint to the other. I’m fairly new to blueprints and have been struggling for many hours to solve this problem, searching for it all over the internet but couldn’t find the solution I’m looking for.

Essentially I’m creating a "Quest giver / Mission starter Actor (In my case called: BP_missionStarter_Parent) that will display a UI with mission details when you approach. So I’ve set up a Variable system that is public for me to easily edit:

Then when I try to Cast those variables to a different blueprint I don’t get it to work. It appears that the object reference on the Cast to is not working. I’ve tested it with a quick debug variable that works, so it has to be something wrong with the Cast To.

Right now I’ve tried to reference the BP_MissionStarter_Parent by using a variable as the BP_MissionStarter_Parent and also with an Object variable and defining the default value to the BP_MissionStarter_Parent

I’ve tried to so many different ways to set up the scripting now, but always end up with the same problem with the Cast to Object Reference. Am I using the wrong type of reference? Or is it something entirely different that is wrong?

Is your reference actually set to something? The ref won’t just link to your bp. You need to set that variable at an earlier point. I remember being very confused with what casting actually does when I first started. I thought I could find my way to referencing any object in the game by stringing a load of casts together but it doesn’t work like that.

Also - I think the term ‘cast’ is a bit misleading - implying you can send something somewhere. What cast really means is ‘let’s see if we can treat this reference/thing as if it’s an X’. This means you have access to all the variables and custom events etc that that type of object has (the cast node gives you this access) - but only if it’s a successful cast. You could plug a machine gun or a tank into the cast (cast to the tank) and tell it to accelerate - an event only available to the tank BP, so the machine gun attempt results in a failed cast. In your case I think you want to put your mission variables into your target BP - presumably your pawn or player controller.

Thank you! I finally got it to work! The problem was that the reference wasn’t set to anything. I assumed that when I wrote the Actor name in the Variable Type it would use the Actor I wrote as the reference, but I was obviously wrong.