i have a Blueprint called test with a pointlight called testlight
im trying to cast that blueprint so i can toggle the light with a keystroke but i keep getting this error
i have a Blueprint called test with a pointlight called testlight
im trying to cast that blueprint so i can toggle the light with a keystroke but i keep getting this error
topdowncontroller is not of the test class so your cast cannot work. what this means is is that your current bp does not inherit from your test class. that probably still doesnt make sense so think of inheritance like this: say you have a ford mustang it inherits from the class car since it has the basic characteristics (4 wheels, basic shape, etc). a boeing 747 would not however since its different. thats a gross oversimplification but just think of a cast like a tree system where a parent class is the trunk then the children are the branches and the children of the children are the leaves. given that analogy you could have vehicle as the trunk, car as the branch, then mustang as the leaves. car inherits the characteristics from vehicle, mustang inherits from car which inherits from vehicle. your issue is that your taking one tree and trying to compare it to a branch in another tree in a way. this is probably a bad explanation.
just know that you need a reference to the actor that you want to be changing and plug that into the cast. so if you were calling this ability from a character you could get overlapping actors then find the closest test actor which would give you a reference. then you use the cast to basically identify the referenced actor. a cast basically just asks is the object in like the one im looking for.
the way you have your script currently you are trying to toggle the vis of a light which doesnt exist in the topdowncontroller bp .
If i can only call keys in the player script, how do i get to toggle the light if it cant be referenced in the player script?
the topdowncontroller bp is the playerscript
keys? are you talking about input events? if thats the case they can actually be called from any bp.
you need a reference to the actor that contains the light so you can target and affect it. there are many ways to get a reference and it depends on the situation as to which method to use. theres traces, public variables, overlap events, etc we have covered this topic an inordinate amount of times on the answerhub.
assuming your topdowncontroller bp is a player controller, and assuming your attempting to do something like a light switch, you could easily get the controlled pawn then get overlapping actors which will return an array then use a find node and search for the object class you need.
you can also use a for each loop as shown below. the script in the example below gets all the actors of light bp class that the character is overlapping then sets the lights intensity contained in the light actor.