Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Create and reference assembly (.asmdef) files at editor-time

Discussion in 'Editor & General Support' started by fc-ts, Jan 12, 2022.

  1. fc-ts

    fc-ts

    Joined:
    Jan 12, 2022
    Posts:
    7
    Hello,
    I'd like to import the Universal Render Pipeline package at runtime, then create a UniversalRenderPipelineAsset.asset file and assign it to the Graphics Settings.

    What I'm trying to accomplish is to access the UniversalRenderPipelineAsset.cs script that would allow me to instantiate a new UniversalRenderPipelineAsset.asset file, I also need to create an assembly file inside my Editor folder and then reference the Unity.RenderPipelines.Universal.Runtime.asmdef assembly file to it.

    I tried to use the Assembly Constructor Api but I'm not sure I'm using it correctly and not even sure it does what I need (i.e. create a new .asmdef file at editor-time).

    A problem is that event though I can find the path of the Unity.RenderPipelines.Universal.Runtime.asmdef file, I don't know how to retrieve it as an Assembly object then (so I can pass it to the Assembly Constructor as a reference).

    Am I trying to do something possible at all?

    Thanks in advance and have a nice day.
     
  2. Create an asmref file in your folder pointing to the URP's asmdef file and your code will compile alongside with the URP code in theory. If I remember correctly you can create it in the editor and it doesn't cause problems if the referenced asmdef doesn't exists (you need to test it though).
     
    fc-ts likes this.
  3. fc-ts

    fc-ts

    Joined:
    Jan 12, 2022
    Posts:
    7
    Thanks, I wasn't aware of asmref files!
    However I cannot find a way to create them from an editor script, do you have a reference for this?
     
  4. I'm not sure why do you want to create it from script, if your code exists otherwise having this file created doesn't hurt.
    But if you really want, just write out a text file with asmref extension in the proper folder:
    Code (CSharp):
    1. {
    2.     "reference": "<name of the referenced asmdef>"
    3. }
    And that's it. That's the asmref file.
     
    fc-ts likes this.
  5. fc-ts

    fc-ts

    Joined:
    Jan 12, 2022
    Posts:
    7
    I'm experimenting with automated builds and wanted to know if I could import and setup the project all at editor-time.

    However thanks for the suggestion, I didn't thought about just creating the file from scratch.
    I think I have what I need, now it's just matter of try things out.

    Thanks again!