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
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.
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.
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
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.
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.
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