Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing material of Volume spot at creation?
#1
Hi, it's me again.

I'm using the volume spot creation with the generator, and can't really figure out how I would change the volume spot gameobject's material's color on spline creation.

As you saw in my last post, each of my splines are created at runtime and generate volume spots as I "draw" the spline. I tried grabbing the gameobject from the generator volume spots component, then creating a new material with my new color, then applying it to said object. It works the first time, but when I "Stop" my game, the gameobject prefab loses its material and now gives an error when I run it afterwards and have to manually re-apply the material.

Then I thought instead I can maybe change the color as the generator is creating instances of my gameobject using the Volume Spots Event system, but this is where I'm stuck. I have no idea how to use the event callbacks. I looked at the API, but there's not really any info on how to use "CurvyCGEventArgs" for example.

Is creating a callback event the best way to modify the color of each instanced gameobject on the spline (they will all be the same color)? If so, what would the function look like in my scirpt?

Here's what I tried, which is obviously wrong  Blush

Code:
public CurvyCGEventArgs ChangeVolumeSpotColor(evt newgameobject)
{
    newgameobject.getcomponent<MeshRenderer>().material....
}



Also, is there a way I can somehow donate money to you or something? You've been a great help and it's so nice to have developers answer customer questions so quickly. And I feel bad asking so many questions... Blush

FYI: I could never leave a review on your asset in the store (or any other for that matter). It always says "Please download this asset to leave a review". Not sure how to "download" your asset, but I've downloaded it with the "Open in Unity" button.
Reply
#2
Hi
  1. Assigning the material to the prefab at runtime leads to that problem because the material you assigned is runtime created, meaning it stops existing once you exit play mode, while the prefab is persistent.
  2. A solution is to use the Input Meshes module instead of the Input GameObjects. This module allows you to set the material as you wish.
  3. The solution you thought about, assigning a material to each created mesh, while is not the best solution, is possible. Here is how to listen on OnRefresh event of a generator. Same event exists also for each module.
    Code:
    using FluffyUnderware.Curvy;
    using FluffyUnderware.Curvy.Generator;
    using UnityEngine;

    public class Test : MonoBehaviour
    {
        void Start()
        {
            GetComponent<CurvyGenerator>().OnRefresh.AddListenerOnce(WhenGeneratorIsRefreshed);
        }

        private void WhenGeneratorIsRefreshed(CurvyCGEventArgs arg0)
        {
            Debug.Log("Refeshed");
        }
    }
  4. Allow me to ask questions about your issue with leaving a review. Can you try to download the asset from both the asset store (on browser), and from the package manager window (which lists assets too if you select that in the selector). Is the issue still present? If so, can you please send me the invoice number so that I contact Unity's customer support? You probably are not the only one with this issue.
  5. Thanks a lot for thinking about donation. You really don't have to, but if you really want to, I will send you details via private message.
Will answer you other post soon.
Until then, have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
(08-10-2023, 10:41 AM)_Aka_ Wrote:
  1. ....The solution you thought about, assigning a material to each created mesh, while is not the best solution, is possible....

Your solution did work, but I didn't realize it would be called each frame. I thought the callback was called only every time a volume spot is added. Is that possible?

The idea, is that I need to make sure the material is the "selected" color, and want to "fade in" (adjust color alpha) the volume spot mesh every time a new one is created. So it would make for a smooth "volume spot" spline animation.
Reply
#4
Btw, for the Review issue, I tried many things and still cannot leave a review.

I tried the following:
- Starting a new blank project, "Re-downloading" the asset from the Package manager.
- Deleting the actual .unitypackage file from the saved location on the computer...
--- Doing a fresh download in the package manager.
--- Doing a fresh download from the website link (which simply opens the package manager in Unity)
- Checking if maybe it was my browser causing this...
--- Deleting all my history and cookies.
--- Trying a different browser.

I'll send you the invoice number by private message.
Reply
#5
(08-10-2023, 06:53 PM)_RicO Wrote: Your solution did work, but I didn't realize it would be called each frame. I thought the callback was called only every time a volume spot is added. Is that possible?

The idea, is that I need to make sure the material is the "selected" color, and want to "fade in" (adjust color alpha) the volume spot mesh every time a new one is created. So it would make for a smooth "volume spot" spline animation.

The OnRefresh event is not triggered every frame, but only when the generator/module is refreshes. If no input changes (the spline, the placed object, etc.) the event is not triggered.

For complex behaviors regarding the materials, you can code your own logic which would keep track of the number of placed objects, and apply the fading when appropriate. Such logic would be triggered in the OnRefresh listener.
Please keep in mind that when refreshing, all the created objects are removed then added. This means that there are no guarantees that the object at position P pre-refresh stays at the same position post-refresh.
The generator uses pooling, so removing/adding objects should not have a significant performance impact.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#6
(08-10-2023, 08:46 PM)_RicO Wrote: Btw, for the Review issue, I tried many things and still cannot leave a review.

I tried the following:
- Starting a new blank project, "Re-downloading" the asset from the Package manager.
- Deleting the actual .unitypackage file from the saved location on the computer...
    --- Doing a fresh download in the package manager.
    --- Doing a fresh download from the website link (which simply opens the package manager in Unity)
- Checking if maybe it was my browser causing this...
  --- Deleting all my history and cookies.
  --- Trying a different browser.

I'll send you the invoice number by private message.

Thanks a lot for trying. I will contact the customer support regarding this.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Volume Spots problem with spacing Bond007 1 3 12-05-2024, 11:17 PM
Last Post: _Aka_
  Duplicate Volume references become null joebain 5 33 11-18-2024, 10:46 AM
Last Post: joebain
  Nested Spline Volume Spot Instantiation merobbins5 3 7 07-26-2024, 09:58 AM
Last Post: _Aka_
  How to use CG Volume Controller j95677 5 12 07-17-2024, 07:15 PM
Last Post: j95677

Forum Jump: