Search Unity

Question Trying to change values of cloned objects independently

Discussion in 'Scripting' started by Jarumba, Jul 16, 2021.

  1. Jarumba

    Jarumba

    Joined:
    Jul 7, 2021
    Posts:
    23
    So I've been stuck on this one all day and now I'm going to reach out to you lovely people.
    to set the scene I'm trying to change properties of an assembler to create different items based on what button i click on from the dropdown menu I create while interacting with them. Problem is that every time I change the item that is supposed to be assembled, it changes it on all the assemblers leading to them all creating the selected item. I'm sure this has to do with both scripts being active at the same time, and the selection effecting both. I'm accessing the dropdown menu by casting a ray to a Assembler Tag, there for accessing both scripts. I want to just asses the script of the object that the ray is hitting, not all of them. Also I'm using visual scripting as I'm a scrub. Below are attached logic.

    material selection.JPG

    So as you can see from the top logic I'm using a raycast to select based on Tag, but this obviously effects all building scripts attached with this script.

    Your help would be greatly appreciated.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    This shouldn't be and isn't the case. Just checking the tag on the object the raycast hit will not somehow magically affect all GameObjects with that same tag.

    I'm not familiar with the visual scripting aspect of this but the behavior you're seeing sounds consistent with your "what to make" variable being static. I'm not even sure if static variables are a thing in visual scripting, but if your "what should i make" variable is static, then all of your assemblers will always make the same thing because a static variable has only one copy that all scripts read and write from. The answer is to not use a static variable, if that's what you're doing.

    Edit:
    There are indeed non such things as static variables in Bolt. It looks like these are the possible variable types in Bolt:
    https://docs.unity3d.com/bolt/1.4/manual/bolt-variables.html

    Make sure you are using an "Object variable" for the "what item to make" variable for your assembler. If you are using a Scene Variable, Application Variable, or Saved Variable, you will see the problem you're seeing.
     
  3. Jarumba

    Jarumba

    Joined:
    Jul 7, 2021
    Posts:
    23
    So I figured out a way around it. Because my Assembler script has the raycasting inside of it, I had to find a way to make sure that the raycast wouldn't activate all scripts. So I ended up doing collision>exposeGameObject and compare that object with "this". Works like a charm!!! just to be clear my variables were object only. Below is the changed flow.
    material selection solved.JPG