How to get an object for casting to a blueprint in the level

Hello,
I’m currently working on a project and am trying to set up a system where you press ‘M’ and get a mission where it chooses a random rock and then the rock checks whether it is the chosen one or not and prints true if it is or false if it isn’t.
I am using casting to reference to a variable in another blueprint is but when casting to the rock blueprint I don’t know what to add as the object. Can anyone help me
Thanks,
Harry

Third person Character blueprint:

​​​​​​​

Rock Blueprint:

​​​​​​​ ​​​​​​​ ​​​​​​​ ​​​​​​​

Hey, after you make the random Integer you have to use a “Get All Actors of Class” to get a reference to the rock bp, take care this can cause lags when you have too many rocks.
I made a quick example for you to better understand.
​​​​​


I made it so that after pressing M and getting a random rock it will also set the Bool for “MissionTarget” to true in that specific rock blueprint.
in your case you check every tick if the rock has the same integer which in your case will always be “1” on each rock.

this is not needed because I can cause Performance loss since every rock in your world will ask the character if it is the right rock or not.

Thanks for your help but what type of variable is ‘Chosen Rock’?

all you have to do is right click on the blue dot on the “Get” block after the get all actors of class. or create a variable and search for your rock blueprint and select Object Reference this is the reference you were looking for.

​​​​​​​

Capture.JPG

Ok, Final question (hopefully): how do you get the mission target variable in the character bp?

you get it from the chosen rock variable, simply drag off the blue and look for “get mission target”. I set up the chosen rock bp exactly like your rock bp, just that you are casting to it which we don’t need anymore because we save the reference in the first step.

OK, it turns out that that wasn’t the final question. When I Run it, it always comes out as false and I get an error saying that it accessed none trying to read the chosen rock variable.
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“large”,“data-tempid”:“temp_143811_1533127713018_761”}[/ATTACH]
I ran an is valid test on the chosen rock variable and it comes out as false. I have tried and tried to find the problem but I no idea so i wondered if you might know the problem.
Sorry for bothering you and thanks for all the help.

did you select the right actor at the “get all actors of class” note? the picture is not working btw :stuck_out_tongue:
also, make sure you got at least one of your rocks placed inside the level.

I’m only getting the same error as you when I have the wrong bp selected, if there is no rock bp in the level or you press Z before M.

Capture4.PNG.jpg ​​​​​​​

None of these seem to be the problem. I have no idea why i’m getting the error so i have sent you images of everything just in case you see something that i have missed.

you don’t need any of that code since we are setting the bool for the “mission target” already in the character bp.

img1.JPGAlso, you only got one rock bp in your level, so if the random integer hits the number 2 or 3 it can’t reference a bp because there is none.


I changed the code a bit, now it will always just chose the max integer depending on how many rock bp’s there are in the level.
but to get the correct item we have to take the length -1 because length will give us the exact number of items in the array, but because array’s
start at 0 we have to subtract with 1 to give the array the correct integer so we get the item we want.
also, make sure to set the “min integer” to 0

Thanks so much, it all works now and I’m really grateful for all the help you’ve given me :slight_smile:

no problem nice to hear that it is working now :slight_smile: