Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Instantiating issues

Discussion in 'Visual Scripting' started by rell023, Apr 28, 2023.

  1. rell023

    rell023

    Joined:
    Mar 29, 2023
    Posts:
    18
    How do I set which prefab class I want to instantiate? I only have an "Original" type input in any of the instantiate game object nodes. If this is explained in the docs just ignore this part, I feel like this is a pretty simple question. I'm going to pour over them tomorrow and will update the post if I find the answer.

    More importantly though, how do I set variables on the instance of the prefab I am creating? In my specific case right now I am creating a projectile, and I would like to give it its target position, target game object reference, and various statistics from the game object that instantiated it. Another use I will have is to set the data, such as item name, item type, quantity, sprite, so forth, on a worlditem class. If you are familiar with Unreal, the effect I am trying to achieve is how you can set public variables on the specific instance you are about to create through the SpawnActor from class node if that helps clarify my question.

    Thanks!
     
  2. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    98
    You should have a list of instantiate game object like on the right. See example for how to do the rest.

    To set a variable, assign it as an object variable at the end of the instantiate. It all happens in the same frame so it's instantly applied. You can add as many as needed for any type.

    upload_2023-4-28_6-24-58.png
     
    rell023 likes this.
  3. rell023

    rell023

    Joined:
    Mar 29, 2023
    Posts:
    18
    Thanks for your response jlbaker2779, it clarified quite a bit. It seems the "Original" type is interchangeable with GameObject type?
     
  4. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    98
    It can be any object you want. I usually use prefabs and don't instantiate existing objects because I am making an MMO with FishNet. I have a folder like so and plop in what I need.

    upload_2023-4-28_18-33-50.png


    Video if you are interested in multiplayer. It's stupid easy to do with VS. Be sure to join the discord if you get stuck. 1000s of people there to help get you going.
    https://fish-networking.gitbook.io/docs/manual/tutorials/videos/visual-scripting