Search Unity

Resolved Updating items with new object variables

Discussion in 'Visual Scripting' started by AdamBlastAllBots, Feb 25, 2022.

  1. AdamBlastAllBots

    AdamBlastAllBots

    Joined:
    Jun 10, 2013
    Posts:
    21
    Hi everyone, I have a basic question that hopefully this makes sense -

    - I have 1 sword.

    - This has 'Weapon' script assigned and 'WeaponDamage' as an object variable.

    - I go on to make 50 swords.

    - I then decide I want to add 'WeaponDurability' as a new object variable.

    Is there any way so every item that has the 'Weapon' script on automatically gets this new object variable assigned in the variables list? Or do I have to go to every object an add it?

    Thanks in advance
     
  2. munchmo

    munchmo

    Joined:
    May 20, 2019
    Posts:
    86
    Yes and no. You can modify your existing script to add the new variable and use it. Object variables don't have to exist on the object before you set them in a graph, however there are certain limitations. First, you have to always check if the variables exists before accessing it by using the Has Variable node. That also means you will only be able to see the variable in the inspector while the game is running.
     
    AdamBlastAllBots likes this.