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

Add prefab to list based on object touched?

Discussion in 'Editor & General Support' started by Zebbi, Jan 18, 2021.

  1. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I want my player to touch an object, add it’s prefab asset to a list and destroy the object. I can then instantiate every prefab on this list later. I’ve tried giving each object it’s own reference to its prefab, but at runtime this reference just becomes its own instance. I think scriptable objects can be used to this, but I’m not sure how. What would the best way of doing this kind of inventory prefab referencing?
     
  2. AbandonedCrypt

    AbandonedCrypt

    Joined:
    Apr 13, 2019
    Posts:
    69
    Store an asset reference / path to prefab (in my case assetbundle) and instantiate from that when needed, maybe? I was dealing with the same issue and only found this workaround to work. I'd be interested in a proper solution, too, because I am unhappy with how undynamic this is.
     
  3. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    What do I store the asset reference in? I could probably find it by comparing the var name to a string on the object I'm colliding with to, but where do you actually store the asset reference?
     
  4. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Could a mod move this to scripting, I realize I've been posting in the wrong forum, lol!
     
    Last edited: Jan 18, 2021