Can't change a Unity 5 Image

NodeCanvas Forums Support Can't change a Unity 5 Image

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #10939
    gadget girl
    Participant

    I just got NodeCanvas and I’ve been reading the documentation and playing around with it trying to figure it out. I thought a simple task would be to create a Behavior Tree that changed the background image based on the value of a string. I wrote a simple script to determine what background to use based on a string variable:

    This code works just fine if I run it all as a script (meaning create a start function that calls it and pass in a variable). But I have not found a way to call it successfully from a Behavior Tree. The strange part is in the console log, I will get exactly what I expect as I pass in variables, but the actual image won’t even change. I’ve attached a screen shot of my Behavior Tree.

    If I’m going about this in completely the wrong way, let me know. The main trouble I’m having is that I haven’t found any examples to work from. Originally I thought an FSM was the way to go for this task, but I couldn’t figure out how to either compare variables or check for when a variable changes. Also I’ve noticed that the only Unity UI types that NodeCanvas seems to have built in is for buttons and sliders. Am I missing a better way to access the UI?

    Any help is welcome.

    Thanks

    Attachments:
    You must be logged in to view attached files.
    #10944
    Gavalakis
    Keymaster

    Hello,

    Hmm. Do you mean that the code runs, but the source image is not set? It seems that you are setting the image on each frame, and the Unity UI might not be able to handle that (haven’t tested, but just a speculation). Would a simple Sequencer with a Wait child and an Execute Function of your NewLocation method will work?

    Regarding examples, there are some examples available to download. Have you checked them out, or are you referring to something different? 🙂

    Comparing variables can be done with the Condition Tasks under “Blackboard” category. For example with the Check Float condition, you can compare floats for equality, non equality, greater, less etc. I am sure I misunderstood this question though since I see you already used one such condition. Can you please clarify what you mean on “how to compare variables”?

    The Button and Slider are only some default available types. If you open up the “Preferred Types Editor” window (Tools/ParadoxNotion/NodeCanvas/Preferred Types Editor”), you will be able to alter the list of available types to you desire, by adding new types, or even removing existing ones that you dont like/want to use. All types in the list in that window, will be available to work with in NodeCanvas. So if you want for example, you are free to add the “UnityEngine.UI.Image” type by clicking the “Add New Type” button there. Doing that will allow you to call methods or get/set properties on an Image component directly, as well as have variables of that type in the Blackboard for example.

    Finally, if what you are after (as far as I understand), is to change the background of the -I presume- adventure game, then indeed FSMs would be a much better fit at doing that, since each state can represent a different location.
    Each state would then have an action to set the image of the background (or even more actions doing other things relevant to the location), as well as transitions from it to other ‘states/locations’ based on some conditions like for example a UI Button clicked, or the player entered a trigger. I would definitely recommend using FSMs for location management.

    Please, let me know if you need ANY clarification on the above at all, or if the above works or not for you.

    Thank you!

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.