Download

UE4 Training: Advanced AI - Variable is Read-Only

Hey all, hope you’re having a good day. Fall semester’s coming up, so probably not.

Let me get right to my issue. I’m trying to break into AI, and I went to watch this Training Twitch video to help. Up till about minute 45 I was doing fine, but then I got stuck. In the video we set up an EnvQueryContext and the connections therein. Here’s where our paths diverge:

27e3f1b641a82afe186c15835e8acad93eebadc2.png

At 45:45 they compile the blueprint and move on, but when I try to compile all I get is “This variable is read-only in this context and cannot be set to a new value.” I went over the video several times and I swear I’ve got everything set up just like they do, so why is mine failing to cooperate?

So, any help is great. Have a good semester.

Hi, I assume that some of unreal exceptions are just not clear enough, but in this case “This variable is read-only in this context and cannot be set to a new value.” means that you could not set a variable located outside the function when the function is marked const (it can be seen in the header - ProvideSingleActor (const)). To fix it up just click on your function entry node, in Graph section open advanced parameter and uncheck Const.

I had the exact same problem. For me the problem was that my variable wasn’t a “Local Variable”. Thanks for asking and thanks for the hint about const, that helped me a lot :slight_smile:

Thank you so much! making my function constant solved a very similar issue for me!