#archived-code-advanced

1 messages · Page 101 of 1

violet depot
#

Because going above 255 seems extrremly unlikely for v1 or v2.

#

And I used strings that I converted to bytes since v3 was of type T (any type)

sage solstice
#

Hello, my mesh is not generating if there are objects on top of them, what can I do? I am new to working with nav mesh so I am confused.

jolly token
#

You might have set the height too tall so navmesh does not get generated there

fringe root
#

Hey guys, I've been looking at implementing some UI and I got some doubts

I see some people saying i just have only 1 canvas, other people saying i should separate Ui elements inside their own canvas.

My problem atm is that i want my mobs to have health bars and also show damage numbers on screen, i feel like the best solution would be get all of thay centralised into one world space canvas as that will be redrawn quite a lot anyway and have common HUD elements in their own canvas, in a separate scene

How does that sound?

sage solstice
sage solstice
jolly token
#

So what you’d want is setting up proper collider rather than just using mesh itself

#

BoxCollider seems like better fit in your case

sage solstice
#

Yeah thats what I tried, it worked thanks again!

next trout
#
public void SaveGame()
    {
    int money = FindObjectOfType<MoneyManager>().currentMoney;
    GameObject playerGameObject = GameObject.FindGameObjectWithTag("Player");
    if (playerGameObject != null)
    {
        Vector3 playerPosition = playerGameObject.transform.position;
        Debug.Log("Saving game. Player position: " + playerPosition);

        SaveManager.instance.SaveGame(money, playerGameObject, playerPosition);
    }
    else
    {
        Debug.LogError("Player GameObject not found. Make sure it has the correct tag.");
    }
    }



void Start()
    {
    // Load saved data
    SaveData data = SaveManager.instance.LoadGame();
    if (data != null)
    {
        FindObjectOfType<MoneyManager>().currentMoney = data.money;
        
        Debug.Log("Loaded player position: " + data.playerPosition.ToVector3());
        
        GameObject playerGameObject = GameObject.FindGameObjectWithTag("Player");
        if (playerGameObject != null)
        {
            SaveManager.instance.LoadPlayerPosition(playerGameObject, data.playerPosition);
        }
        else
        {
            Debug.LogError("Player GameObject not found. Make sure it has the correct tag.");
        }
    }
    else
    {
        Debug.LogWarning("No save data found. Starting with default values.");
        FindObjectOfType<MoneyManager>().currentMoney = 0;
    }
#

theres more to the code but this is where im figuring the problem is at

sly grove
#

I mean presumably it would be somewhere in the code that positions the player or the camera at the start of the scene

#

Maybe SaveManager.instance.LoadPlayerPosition(playerGameObject, data.playerPosition);?

#

there's very little context shared here for us to help

tired fog
#

Hellou, I wonder if there's a way to vectorize two non aligned arrays in context of jobs and burst.
By non aligned i mean:

  • Array A: 4 important values in each set without data in between
  • Array B: 4 important values and one non important in between setd

The 4 important values of each array should match. So i could reinterpret the first array from float to float4. But the second I wouldn't be able to because the nonimportant value would fall between the rellevant floats4 and it would no longer match

#

Note that this is a simplified case. In the real scenario sizes of everything are unknown until scheduling the job and can vary a lot of size

#

My current solution for now is to not vectorize and do some indexing work

#

But if there's a know way to vectorize data that way i would get some boost

hazy brook
next trout
hazy brook
next trout
#

yes, The childs of the tag player are not being loaded or saved correctly

hazy brook
#

thats something that would happen in the SaveManager script

#

thats more likely where the issue is

next trout
#

gotcha, Ill have more of a look after work

#

Im only saving position, Would i need to save rotation aswell?

hazy brook
#

id say if you want to you can, but for most games im sure its not that important

wooden moat
#

Hi im trying to make a rhythm game and setting the songposition value using dsptime, yet in unity the time of the song seems to be nearly a second ahead of what it shows in audactiy and i don't understand why. the audio clip has decompress on load, the audio settings are for best latency, play on awake is off and the clip is started in Start, and this isnt an audio offset issue, since im looking at the seconds here and unity is ahead of audacity. the first drop happens at 1.948 in audacity but around 2.5 in unity, by looking at the songpositiontext.
here's the code that handles the songposition

#

    private void Awake()
    {
        musicSource = GetComponent<AudioSource>();
    }

    void Start()
    {

        songPosition = 0;
        songPositionRounded = 0;
        songPositionInBeats = 0;
        songPositionCurrentBeat_int = 0;
        songPositioninBar = 0;
        dspSongTime = 0;

        //Calculate the number of seconds between each beat
        secPerBeat = 60f / songBpm;

        //Record the time when the music starts
        dspSongTime = (float)AudioSettings.dspTime;

        //Start the music
        musicSource.Play();
    }

    void FixedUpdate()
    {
        //determine how many seconds since the song started
        songPosition = (float)(AudioSettings.dspTime - dspSongTime);

        Debug.Log((float)dspSongTime);
        Debug.Log((float)AudioSettings.dspTime);

        //determine how many beats since the song started
        songPositionInBeats = songPosition / secPerBeat;
        songPositioninBar = songPositionInBeats / beatsPerBar;

        if(songPositionInBeats > songPositionCurrentBeat_int + 1)
        {
            songPositionCurrentBeat_int++;
            pc.changeFrame();
        }

        if (songPosition > songPositionRounded + 0)
        {
            songPositionRounded++;

            //backgroud.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
        }


        songPositionText.text = songPosition.ToString();

    }
}
    
    ```
keen ferry
#

is it possible to code something where you can colide with something from both sides

thin mesa
#

what does it mean to "colide with something from both sides"

keen ferry
#

yeah

#

i mean like you know how there are both sides in shader graphs and you can only colide on one side with a mesh

thin mesa
#

you can set up your physics queries to hit backfaces, i don't think rigidbodies detect collisions with backfaces though

keen ferry
#

oh dang

grizzled bridge
#

Hey, is anyone here who once tried git subtree or git worktree for reusing code? I am writing a bachelor thesis on the subject of code sharing and have not yet found anyone who has had any experience with it

jolly token
next trout
#

Can someone help me understand why its not saving or loading my camera position correctly, but its loading and saving my player position correctly?

upbeat path
jolly token
#

BinaryFormatter ☠️

thin mesa
next trout
#
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:45)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)

Saving game. Player position: (-53.62, 0.00, -37.70)
UnityEngine.Debug:Log (object)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:14)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)

Says its saving and load the camera position correctly, But my camera is not being loaded correctly its being loaded into the ground.

next trout
#

Just switched to XmlSerializer

#

Im using the Starter asset, Its saving and loading the MainCamera position correctly, But the camera is still in the ground on loading

thin mesa
#

you're assigning the camera's position directly but using cinemachine. you need to change the vcam's position

next trout
#

is there a easier way to save the whole PlayerArmature GameObject with all the cameras etc, Instead of having the save the position of the PlayerArmature and then the Position of the Cameras etc?

grizzled bridge
frozen imp
fresh spruce
#

Okay, thanks

frozen imp
#

@fresh spruce Moving means deleting original one. Don't cross-post

scenic forge
wooden moat
scenic forge
#

Yes, there's absolutely no consistency of Play's latency, so different devices, and even different plays of the same device in the same session, may have different offsets and mess up the player.
Here's someone else asking about rhythm game timing and I've given a more detailed answer in the thread: #1096003362199191582 message

next trout
#
Saving game. Player position: (-48.74, 0.00, -40.21)
UnityEngine.Debug:Log (object)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:14)

Camera position saved: (-0.46, 1.40, -0.01)
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:42)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)

PlayerCameraRoot position saved: (0.00, 1.38, 0.00)
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:52)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)

PlayerFollowCamera position saved: (-0.46, 1.40, -0.02)
UnityEngine.Debug:Log (object)
SaveManager:SaveGame (int,UnityEngine.GameObject,UnityEngine.Vector3) (at Assets/Scripts/Saving/SaveManager.cs:53)
MainGameController:SaveGame () (at Assets/Scripts/Saving/MainGameController.cs:15)


Loaded player position: (-48.74, 0.00, -40.21)
UnityEngine.Debug:Log (object)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:40)

Loaded PlayerFollowCamera position: (-0.46, 1.40, -0.02)
UnityEngine.Debug:Log (object)
SaveManager:LoadGame () (at Assets/Scripts/Saving/SaveManager.cs:74)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:35)

Loaded PlayerCameraRoot position: (0.00, 1.38, 0.00)
UnityEngine.Debug:Log (object)
SaveManager:LoadGame () (at Assets/Scripts/Saving/SaveManager.cs:73)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:35)

Loaded camera position: (-0.46, 1.40, -0.01)
UnityEngine.Debug:Log (object)
SaveManager:LoadGame () (at Assets/Scripts/Saving/SaveManager.cs:72)
MainGameController:Start () (at Assets/Scripts/Saving/MainGameController.cs:35)
stuck plinth
#

can you just step through it in the debugger and see if the value is correct at each stage? it should be fairly easy to see if the value and name are what you expect in the loaded save data

sly grove
#

I really doubt the issue has anything to do with the saving/loading

#

it's probably just cinemachine not being configured properly

next trout
#

im using the starter asset controller, Its is configured properly

sly grove
#

Saving and loading camera positions is useless if you're using cinemachine

#

the position of the camera is entirely dependent on your virtual camera settings

#

those are the things that would need to be saved/loaded

#

(assuming parts of it are changing)

next trout
#

this is my player

sly grove
#

the stuff inside there

next trout
#

Gotcha, I think i realize whats messing up

next trout
#

it works. 2 days to figure it out, finally works.

next trout
#

nvm

#

Figured out why its doing it tho, Idk how to fix it.
The PlayerFollowCamera sets it self on the ground
if i dont use the PlayerFollowCamera the save and load work fine, But then the mouse look doesnt work and you can only move the body and not use the mouse to look around. So i need to use it, But when using it it spawners on the floor

fickle tinsel
#

Does anyone have any advice on how to implement different controls for different game states (e.g. pause menu, world map, combat, dialogue)?

So far my solution has been to enable/disable game objects with MB components that handle interpreting player input on game state change (on pause, disable all other input listening components except pause menu). I was thinking maybe somehow implementing the disabling/enabling of input listening components as a FSM might be a good idea.

charred thunder
# fickle tinsel Does anyone have any advice on how to implement different controls for different...

One way to solve this would be making use of the new input system. There you can have different action maps, which could respresent your game states, e.g. menu, combat and so on. In these actions maps are the different actions you could perform in these states. Those action maps can easily be enabled/disabled. How you handle this depends on your needs, there are some builtin components which might be good enough for your specific needs, or you have the possibility to implement your own inputmanager/reader whatever. There you could listen for your state changes and enable the respective maps.

tired fog
#

What should I be looking for when trying to improve burst compiled code?

glacial sentinel
#

https://gyazo.com/c164d6739aa00b44329eb87ae658808c Hey all, I updated unity from 2021.3.19 to 2021.3.38 and now during initializion the scene reference for some scripts is wrong. In this script all the components on a gameobject are being initialized and managers are being found for the requested variables, however, for some scripts it gives a different scene reference (one that is not loaded) while they are all on the same gameobject and should have the same scene reference. Any idea what to do about this?

sly grove
#

That's just an invalid scene aka not a scene at all

glacial sentinel
sly grove
#

Wdym by "wait until the scene reference became valid"?

sly grove
#

It's hard to help a lot here without seeing the code

sly grove
#

If gameObject.scene is not valid it's probably because you're running code on a prefab

glacial sentinel
sly grove
#

Prefabs don't exist in a scene

#

They're assets

glacial sentinel
#

oh I mean instances of a prefab

sly grove
#

I think your code is actually running on a prefab

#

Not an instance of one

#

But I'm really taking a guess from very little information here

#

It's unclear where this scene variable comes from

glacial sentinel
#

hmm but I don't get how that's even possible, doesn't code on a prefab only run when it's instanciated

sly grove
#

Please show some code

sly grove
#

You can call a function on a prefab, no problem

glacial sentinel
#

well basically there's an autoInit that you can inject certain classes too

sly grove
#

Ok so you're using some kind of DI framework

glacial sentinel
#

Yeah

#

Then it checks the dependencies it's looking for and tries to intialize it

#

but already in the AutoInit class where it all starts I have the invalid scene reference for some of the components on the prefab (or what I thought would be the instances)

#

and meanwhile other components run just fine with proper scene references

#

and well it worked as well on the previous version so not sure why it would run on the prefab now and not before

sly grove
#

I don't really know how this DI framework works so it's hard to say

#

And it's unclear what code you're debugging above

#

Or what class it's in

glacial sentinel
#

so in the AutoInit class this Init function is run on Awake and then calls the fixdependencies which calls the injectdependencies

#

This Injectdependencies is what the gif is from and where the invalid scene causes a crash

sly grove
#

Ok but where does the code run that depends on the dependencies having been injected?

#

The code that's causing you trouble in the first place

#

It's this code?

glacial sentinel
#

so this line basically because the scene is invalid when trying to look for the manager

sly grove
#

Where's that line?

glacial sentinel
#

but I figured that's just a symptom of the issue and the cause is the invalid scene reference

sly grove
#

That doesn't appear to be part of InjectDependencies

glacial sentinel
#

so basically that line with the actual exception is one more level down in the get function from the managers class

sly grove
#

I mean...

#

I don't see how Awake is running on an object not in a scene

#

Can you just debug that?

glacial sentinel
#

btw I didn't write this code myself, so it's rough navigating it for me too

sly grove
#

Like can you see Awake running where the gameObject.scene isn't valid?

#

And if so can you check which object that's happening for and what its instance id is?

glacial sentinel
#

It's currently happening for 3 different Objects in this scene, everything else still runs fine

#

Instance id for this object is : 58386

sly grove
#

can you show the stack trace at the time where you're stopped at this breakpoint?

#

something weird is happening

glacial sentinel
#

okay this is interesting, it originates from the exact same function

sly grove
#

Looks like this object depends on some other objects which ulktimately depend on this one

#

so it brings you back to this instance which isn't fully created yet

glacial sentinel
#

yeah that makes sense

sly grove
#

There also seems to be some UniRX observable thing going on in the middle there.

tired fog
#

How can I initialize a subsection of a native array to a specific value?
I tried this

NativeArray<float> temp = new NativeArray<float>(height.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

UnsafeUtility.MemSet(temp.GetUnsafePtr(), Value, height.Length);

UnsafeUtility.MemCpyStride(settings.global_pr, height.Index*settings.pointsLength, temp.GetUnsafePtr(), 0, sizeof(float), height.Length);

temp.Dispose();

and it crashes unity

tired fog
#

float

sly grove
tired fog
#

(byte)float also crashes

sly grove
#

right because there's something off about this

#

MemSet's length parameter is probably expressed in bytes

#

but whne you do new NativeArray<float>(height.Length

tired fog
#

also tried multiplying by sizeof(float) and still looking weird

sly grove
#

that's in "number of floats"

sly grove
#

UnsafeUtility.MemCpyStride(settings.global_pr, height.Index*settings.pointsLength, temp.GetUnsafePtr(), 0, sizeof(float), height.Length); this one, or the MemSet one?

tired fog
#

i made a job to do that before

[BurstCompile(FloatPrecision.Standard, FloatMode.Fast, CompileSynchronously = true)]
internal struct ConstantJob : IJobFor
{
    float Value;

    [NativeDisableContainerSafetyRestriction] [WriteOnly]
    NativeArray<float4> globalMap;

    IndexAndResolution target;
    
    int verticesLength;
    public void Execute(int i)
    {
        globalMap[i + target.Index*verticesLength] = Value;
    }

    public static JobHandle ScheduleParallel(NativeArray<float4> globalMap, 
        float Value, IndexAndResolution target,
        int arrayLength, JobHandle dependency) => new ConstantJob()
    {
        globalMap = globalMap,
        target = target,
        verticesLength = arrayLength/4,
        Value = Value,
    }.ScheduleParallel(target.Length/4, target.Resolution, dependency);
}

but I felt it was too much to just initalize a part of an array

tired fog
sly grove
#

You put 0 in for sourceStride?

tired fog
#

nvm crashed

glacial sentinel
#

for some reason this line triggers the awake of the autoInit script again although I don't get why as it's just setting the parent for the original instance

tired fog
sly grove
#

and what is container?

#

those could be properties

#

which could be doing anything

sly grove
#

Looks like maybe one of them is probably UnityRxObservable or something?

sly grove
tired fog
#
Received signal SIGSEGV
Obtained 62 stack frames
0x00007ff6350ff98e (Unity) UnsafeUtility_CUSTOM_MemCpyStride
0x00000241828ce345 (Mono JIT Code) (wrapper managed-to-native) Unity.Collections.LowLevel.Unsafe.UnsafeUtility:MemCpyStride (void*,int,void*,int,int,int)
0x00000241828cde0b (Mono JIT Code) sapra.InfiniteLands.Nodes.ConstantNode:ProcessData (sapra.InfiniteLands.GenerationSettings) (at 
sly grove
#

basically it means you stepped out of bounds on memory

#

unsafe for a reason 😉

glacial sentinel
#

it's a chunk container that's holding the asteroids in this case (not sure how the chunk code works yet, haven't seen that part of this codebase yet)

#

but I checked and all the objects with this issue are chunk objects so this is proably the cause of it

#

Already big thanks in advance @sly grove , you've been a big help to get me on the right track

misty glade
#

Anyone ever used UGS: "Cloud Save" - I want to store a player JSON file somewhere easy/convenient - but cloud save looks like KVP based storage.. Part of me says it's ok to stuff a json blob in a KVP but I'm not sure what kind of side effects that'll have - escaping characters and all that

#

I could also serialize it as a byte[] to make user tampering a little more inconvenient but I'm not too worried about that - it'd require some deseralization tools above and beyond a text editor for support to edit in some prizes for pissed off customers. 😛

#

(Also I'm interested in any performance feedback - especially if I'm doing something like await CloudSaveService....LoadAllAsync() before letting a user play

fickle tinsel
#

Not me exactly, but I vaguely understand what you’re saying. I’ve learned a bunch getting a gameCI container working for me.

Wait omg the il2cpp question disappear… no!

fickle tinsel
sage radish
#

There's an undocumented attribute used by Unity to mark a class to use eager initialization. It's not public, but you can define it yourself, it just needs to be in the right namespace with the right name:

namespace Unity.IL2CPP.CompilerServices
{
    /// <summary>
    /// This is used to indicate to IL2CPP that the static constructors should be executed eagerly at startup
    /// rather than lazily at runtime.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
    internal class Il2CppEagerStaticClassConstructionAttribute : Attribute
    {
    }
}
fickle tinsel
#

I was just going to say “I don’t know but I do know Unity builder uses binaries packaged with Unity editor; I’d read the build log and see what commands are being run and maybe try to run the commands outside of Unity builder”

sage radish
#

I can't remember the name of the user who asked the question 😔

fickle tinsel
fickle tinsel
sage radish
# fickle tinsel Can you elaborate on this? For my own education— feel free to over explain

By default, IL2CPP will match the behavior of C#, where if you have a static field in a class initialized to some value, like:

public class MyScript : MonoBehaviour
{
    private static int randomNumber = Random.Range(0, 100);
}

the Random.Range will not be called until MyScript is used for the first time in some capacity. Instantiated, or a static method called on it. IL2CPP does this by adding a check in every "entry point" of the type to check if it's been initialized yet, and initialize it if not.

That's cool, but now that means it will always perform that check, even after it's initialized. This attribute avoids that by telling the IL2CPP transpiler to initialize this class at startup instead, meaning the Random.Range will get called right away.

#

With lots of types and lots of static fields, this could significantly increase loading time if it was enabled by default.

#

And it wouldn't match the behavior in C# Mono, which doesn't have any eager static initialization, leading to potential bugs that only happen in IL2CPP builds.

fickle tinsel
sage radish
#

There is also a documented attribute for other IL2CPP optimizations, [Il2CppSetOptions]. But it's the same way, where it's not actually defined anywhere, Unity tells you to copy it from a .cs file in the Unity editor install folder, but as long as the type name and namespace matches, you can just write it yourself in any file.

#

Now, I haven't used Il2CppEagerStaticClassConstruction myself, and can't find any threads about others using it, so maybe it doesn't work or has some caveats. But it's used in Unity.Mathematics, which is just a package with source code which is compiled with the rest of your code, so I think it should work, unless Unity has specific assemblies whitelisted, which would be weird.

fickle tinsel
#

Cool, thanks for sharing all this. Hopefully the original asker comes back and sees some of this conversation.

worldly pecan
#

https://issuetracker.unity3d.com/issues/invalidoperationexception-when-using-asyncgpureadback-dot-requestintonativearray

Does anyone have any updates on this issue? Is AsyncGPUReadback.RequestIntoNativeSlice() working for anyone? I have some data that's managed by a large native array and I need to use NativeSlices to copy data to it--I would really like to not have to copy it to a temp native array.

sage radish
worldly pecan
#

yeah--I was hoping they'd eventually change it so the safety checks occur on the native slice

sage radish
# worldly pecan yeah--I was hoping they'd eventually change it so the safety checks occur on the...

I'm not sure if this would work, but what about creating a new NativeArray that's pointing to a slice of the already allocated NativeArray?
You can use this method to create a NativeArray from an existing pointer:
https://docs.unity3d.com/ScriptReference/Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray.html
And use this method to get the pointer from a NativeArray:
https://docs.unity3d.com/ScriptReference/Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.GetUnsafePtr.html

worldly pecan
sage radish
#

To offset the pointer, you'll need to cast the void* to T*, whatever the element type of your array is, and then you should be able to just do pointer += startIndex

sage radish
worldly pecan
sage radish
#

Otherwise, the ownership of the memory is moved.

worldly pecan
#

Oh that makes sense tysm

worldly pecan
# sage radish The allocator should be set to Allocator.None in this case.

I got it to work! You can indeed get a slice of a native array like this, I just needed to fidget with the saftey handle.
https://forum.unity.com/threads/convertexistingdatatonativearray-and-atomicsafetyhandle.878575/

Just added one more line to make it work.
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref nativeSlice, AtomicSafetyHandle.GetTempMemoryHandle());

livid kraken
#

Does anyone know how the rag-doll wizard actually calculates the mass ratios ?

regal olive
#

Currently trying to implement a URP tessellation shader and I'm getting some really weird errors
It's saying there's an unterminated conditional expression on line 606:

clip(alpha - surfaceDescription.AlphaClipThreshold);```

Weirdly though the error doesn't go away even after I comment out the code
```c
                // #if _ALPHATEST_ON
                //     half alpha = surfaceDescription.Alpha;
                //     clip(alpha - surfaceDescription.AlphaClipThreshold);
                // #elif _SURFACE_TYPE_TRANSPARENT
                //     half alpha = surfaceDescription.Alpha;
                // #else
                //     half alpha = 1;
                // #endif```

Why it also says I have no vert/frag I have no idea
If I completely delete all the frag code except:
```c
            half4 frag(DomainOutput tess) : SV_TARGET
            {
                return half4(1, 0, 0, 1); 
            }```

It now decides the error is on this line:
```c
                #ifdef _NORMALMAP
                    float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
                    float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz);

                    inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
                    #if _NORMAL_DROPOFF_TS
                        inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld);
                    #elif _NORMAL_DROPOFF_OS
                        inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
                    #elif _NORMAL_DROPOFF_WS
                        inputData.normalWS = surfaceDescription.NormalWS; // Error!!!
                    #endif
                #else
                    inputData.normalWS = input.normalWS;
                #endif```

Anyone know what's going on here?
#

Ah nvm got it. Should have just gone with the most obvious and simple answer. I was missing an #endif

stray bridge
#

Hey yall, I need help with steam workshop implementation for custom maps ONLY.

At the moment in my game I have a script that picks a random prefab from a list of prefabs to generate as a map every few in-game rounds.
So the way it works in simple terms is I have a list of prefabs for maps and it picks one semi-randomly to generate
The prefabs are just FBX geometry with read/write permissions and some empty transforms with tags. Each of the FBX objects (from the geometry) have a tag and layer too
What I'm trying to figure out, is how do I make these prefabs exportable (idk into what kind of file format), and then loadable from a folder in the built-application folder.

Should be simple enough in concept but I have no idea where to start as obviously building an application encodes everything

stuck plinth
upbeat path
#

dont cross post

modern yarrow
autumn basalt
#

Is there an AI tool where you can upload your codebase, that will detect logic errors in the code?
The simplest example would be something like:

    Debug.Log(i.ToString());
}```
And then I could ask it, why does my code only print 1-4 and not 5?
But then for complex issues in large codebases
#

ChatGPT can do this a little, but not really and not across multiple files (maybe the paid version can?)

upbeat path
autumn basalt
#

there I fixed it, I'm sure that's very helpful to my actual question

upbeat path
#

to answer your question, I think MS CoPilot can do that

#

you would definitely have to use an AI which actually understands code which GPT etc do not

autumn basalt
#

MS CoPilot seems worse than Chat GPT

upbeat path
#

this is the limitation of LLM's, just because they produce something that looks like code people think it is writing code. It is not, it is writing text that just happens to compile (sometimes)

dusty wigeon
autumn basalt
#

I know for example there's AI where you can just upload a book and it will summarize it for you, even generate prompts if you need to study it

upbeat path
#

but a book is not code

autumn basalt
#

Doesn't seem too far fetched to be able to do the same with "understanding" code

#

code is just another language not?

upbeat path
#

no

upbeat path
autumn basalt
upbeat path
autumn basalt
#

but yeah I do not understand how LLM's work

#

neither do I really care

#

I'm sure someone will come up with an AI that can detect logic errors in complex code soon enough

#

maybe I'll try the paid version of MS CoPilot for a month

tiny pewter
#

there actually are some tools to examine the "logic error" in your code but not using ai, by defining the logic and state and check if your program works (ie not volatile the rules) under some states of your program iirc

tiny pewter
#

In the context of hardware and software systems, formal verification is the act of proving or disproving the correctness of a system with respect to a certain formal specification or property, using formal methods of mathematics.
Formal verification is a key incentive for formal specification of systems, and is at the core of formal methods.
It...

thin jackal
#

Any tips for using multiple threads in unity?
Target platform: Windows and Mac
Context: Working on my thesis integrating some AI technologies into a game context. Since i am trying to reduce time to first byte latency i am making multiple calls to my speech synthesis service, and while it is stable now, i would like to move the synthesis to work independently from the main thread, as how i see it, the only place i really need to think about the main thread when it comes to speech synthesis, would be when i add the audio to the audio buffer.

So i guess what i am wondering is whether i can use C# Thread or similar and still expect the project to compile into a working a working executable for mac or windows.

(Not that i cant just test my thesis without compiling it, just think it would be good for my writeup to be able to say that it also works when compiled)

Since i might have many external web api calls etc, using coroutines and with stuff like waituntil, quickly becomes messy when trying to avoid bad timings.

sage radish
thin jackal
#

@sage radish Ah that’s good news, appreciate the help ^^

sage radish
thin jackal
#

@sage radish Yes that’s what i am doing 🙂 first i used OnAudioFilterRead, but i changed to PCMReaderCallback as i found it to be more fitting for my project. But good to know that i found the two options you mentioned, means i am going in the right direction.

sage radish
thin jackal
#

@sage radish oh it does, Do you know by how much ?, i mean i could go back to the OnAudioFilterRead solution, just need to implement the workaround for another library. Basically i use a library called uLipSync, which uses OnAudioFilterRead, so i had to Call a function in the library to make sure it worked as normal

sage radish
thin jackal
#

Ill have to look into that

thin jackal
#

Pcm gave 390ms so close

#

Though didnt Get stutter with it like i did with OnAudioFilterRead, though i guess ill take one last look at this issue before making a choice

sage radish
thin jackal
#

right, that makes sense. Guess ill have to fix something with the buffer then. I mean, with OnAudioFilterRead i think it was something like 5ms from first byte chunk received from the synthesiser to it being read in OnAudioFilterRead, and the stutter is really only in the beginning, and maybe now and then if i dont remember wrong.

sage radish
thin jackal
#

actually that might be a good idea. i guess i could calculate the expected byte size given my audio format for the specificed amount of time in ms, and when i receive audio ill wait until i have received that amount of bytes ?

#

in my case i guess that would be 2646.0 bytes for 30ms. (high quality audio, so could probably reduce latency by choosing worse audio quality if necessary.

thin jackal
#

nvm i that didnt make sense haha

scenic forge
#

(Also need to take into account network speed, you are making the assumption that your download speed is always faster than playback speed, or at least fast enough to play until the end without pauses)

thin jackal
#

@scenic forge ah yeah ill have to look into that as well.

scenic forge
#

I'm not sure how much that matters in the context of your original question though, "needing to take into account slow downloading speed" and "buffering until there's enough data to play the rest without interruption" are problems and solutions not unique to AI speech synthesis, but anything that needs to be transmitted across slow network in general.

#

You can perhaps leave "to improve experience in slow network consider similar approaches to video buffering" as a remark and focus more on things that are specific to AI speech synthesis, such as streaming the output while synthesizing like how LLMs stream their responses.

thin jackal
#

@scenic forge i mean i think you are right, though since i am inherently just making a demo for my thesis i am allowed to have limiations. So if i cant find a solution to this within the next few days, then ill probably just use the least stuttery version i have. At the moment i read my LLMs incoming stream and wait until i have N number of sentences, then i send that to be synthesised. just to kind of work around the latency.

worn abyss
#

can anybody help me to print an image by script in unity ? 🥲

#

print by printer

compact ingot
worn abyss
#

no im sure its possible to print by code

compact ingot
#

ofc you can print via code, but the libraries for doing that easily are not part of the unity runtime

hoary plinth
#

I'm attempting to create a sort of Field of View cone effect. It's working for the most part, except it only works correctly if the look at point and the player are on the same y coord. If you are above or below that value it starts to get skewed but not exponentially so and only by a few degrees.

#

Here is the code I'm trying to use to calculate things: private void ```LateUpdate()
{
if(UseGetFoV)
fov = GetOriginVertexAngle();
if(UseSetAim)
SetAimDirection(PortalObject.transform.position - origin);
angle = startingAngle;

        verts = new Vector3[rayCount + 1 + 1];
        uv = new Vector2[verts.Length];
        triangles = new int[rayCount * 3];

        verts[0] = origin;
        currentOriginPoint = origin;
        int vertIndex = 1;
        int triIndex = 0;
        // Set layer mask to exclude character colliders;
        for (int i = 0; i <= rayCount; i++)
        {
            Vector3 vertex;
            RaycastHit2D rayHit = Physics2D.Raycast(origin, GetVectorFromAngle(angle), viewDistance, layerMask);
            if (rayHit.collider == null)
            {
                vertex = origin + GetVectorFromAngle(angle) * viewDistance;
            }
            else
            {
                vertex = rayHit.point;
            }
            verts[vertIndex] = vertex;
            if (i > 0)
            {
                triangles[triIndex + 0] = 0;
                triangles[triIndex + 1] = vertIndex - 1;
                triangles[triIndex + 2] = vertIndex;
                triIndex += 3;
            }
            vertIndex++;
            angle -= angleIncrease;

        }

        fovMesh.vertices = verts;
        fovMesh.uv = uv;
        fovMesh.triangles = triangles;
        fovMesh.RecalculateBounds();

    }


    private Vector3 GetVectorFromAngle(float angle)
    {
        float angleRad = angle * (Mathf.PI / 180f);
        return new Vector3(Mathf.Cos(angleRad), Mathf.Sin(angleRad));
    }```
#

Mostly using code from CodeMonkey's FoV tutorial, but can't figure out why the angle isn't lining up as expected.

#

In the left image the player char y = 0.355 in the right the player y = 1.071. If it works correctly the FoV should expand to fit the space between the green points on the right, and set the center of the FoV as the point between those points.

long ivy
#

I find it suspicious you're using world space coordinates for mesh construction. Are you sure it's skewed and not simply rotated? Atm the mesh will only be correct if it's rendered by a mesh renderer at the origin with identity scale and rotation

hoary plinth
#

Sorry let me rephrase, the mesh is correct. The aim point is off from center. So I can turn off the SetAim and manually change the starting angle so it fits perfectly between the two points. It is only off when the y of the character transform is above or below the y value of the target point.

#

I'm thinking it has something to do with the Atan2 used to get the angle from vector. ```public void SetAimDirection(Vector3 dirToPortal)//Vector3 dir)
{
float angleToStart = GetAngleFromVectorFloat(dirToPortal);
startingAngle = angleToStart + (fov / 2f);
}

    private float GetAngleFromVectorFloat(Vector3 dir)
    {
        dir = dir.normalized;
        float n = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        if (n < 0) n += 360;
        return n;
    }
    private float GetOriginVertexAngle()
    {
        Vector3 innerNPos = InnerN.transform.position;
        Vector3 innerSPos = InnerS.transform.position;

        float n = Vector3.SignedAngle(innerNPos - origin, innerSPos - origin, Vector3.up);
        if (n < 0) n += 360;
        return n;
    }```
long ivy
#

What happens if you translate the player a few units in the +x direction?

hoary plinth
#

I when x is changed the fov will increase or decrease to fit between the green points. As far as I can tell this is calculating correctly regardless of position.

sly grove
#

That would imply you should use Vector3.forward or Vector3.back as the axis

hoary plinth
#

I had it on forward originally. I've changed it a few times when debugging the aim issue.

sly grove
#

seems worth a Debug.Log or two to verify it's working properly

hoary plinth
#

I think what I need to do is use SignedAngle to get the angle between the portalCenter dir and vector3(1,0,0).

hoary plinth
#

Got it most of the way now. What I needed was the angle from the x axis down to the top of the mesh to find the starting angle. This is what I used to find the correct angle. private float GetStartingAngle(Vector3 centerDir) { centerDir = centerDir.normalized; float n = Vector3.SignedAngle(Vector3.right,InnerN.transform.position - origin , Vector3.forward); if (n < 0) n += 360; return n; } It doesn't work on the right side of the portal, but that may be due to using vector3.forward I suspect. So need do that better and it should be fulling working.

#

Man that was haunting me.

worn abyss
#

i wanna open an application by javascript in unity... is there anybody to help me ? 😦

#

i just want to launch an application from path when my webgl export is starting

#

i've searched a lot but i've didn't find correct code for javascript

trail quail
#

Is there any way to have unity test runner output failed assertions to console?
or make it so that you can click a stack trace?

#

(editor test specifically)

trail quail
#

sorry i donno if ppl watch both sections

#

or if this would be advanced or not

trail quail
upbeat path
#

based on the level of questions in general, yes I would say it's advanced

trail quail
#

also, if anyone uses rider - is there any way to make rider auto break on an exception thrown in test runner?

flint sage
#

Yes, go to the breakpoint settings and enable any exception in the exceptions list

flint sage
trail quail
flint sage
trail quail
fair hound
#

I have encountered a really weird problem with one of my functions, it seems that if the function is provided a negative number, it always returns 0. This is odd because its a simple function thats supposed to still be able to produce results for negative values. It got even stranger when I tried doing Mathf.Abs() inside the function on the input value, and it would still return 0. Its only if I do Mathf.Abs on the value before I make the function call that it produces a nonzero result. Is there anything I can do to fix this?

public float Evaluate(float slip)
{
    return _peak * Mathf.Sin(_shape * Mathf.Atan(_stiffness * slip - _curvature * (_stiffness * slip - Mathf.Atan(_stiffness * slip))));
}
long ivy
#

with what parameters?

#

I slapped in -0.5 (slip), 1f, 1f, 1f, 1f for those values in order and out comes a negative number just fine

fair hound
#

in engine?

fair hound
#
float
    slipRatio = radialSpeed / localVelocity.z - 1,
    slipAngle = -Mathf.Atan2(localVelocity.x, Mathf.Abs(radialSpeed)) * Mathf.Rad2Deg;

float
    frictionClampX = normalForce * sidewaysFrictionCurve.Evaluate(Mathf.Abs(slipAngle)),
    frictionClampZ = normalForce * forwardFrictionCurve.Evaluate(Mathf.Abs(slipRatio));

this is the context of the usage, as you can see im currently placing abs on the function input because of the issue

long ivy
#

are you doing weird things that might mangle memory? That's a weird take

fair hound
#

oh my god im lobotomized

#

I had an animation curve named a variable that im now using for something else

#

damn, yep Im just dumb. Cant believe I spent an hour on that.

#

Thanks tho

torpid echo
#

I have a cube that can move left,right,forwards and backwards and i want it to move up and down when it hits a object. I've gotten it to do that but it functions really weirdly and does not deal with corners except in very rare occasions. It also somtimes makes it so when i go forward i actually go backwards and then i have to press the inverted keys for it. and instead of the object going up a wall when i try walk onto them it will actually try walk down it unless i press down which actually goes upwards.

I was hoping someone could have a look at my code and see what the issues might be.

Code: https://gdl.space/azazoqafir.cs (I Apologise for the Super messy Code)

wispy rose
#

I cannot seem to successfully connect either Visual Studio or Rider to the AssetImportWorker Unity instances. Is there a command-line option needed to turn on debug mode so I can debug importer code running there?

fickle tinsel
#

For a multiplayer game like Helldivers, is there anything to be aware of if I wanted to implement bug behavior as a server authoritative behavior tree?

I don’t think I need to clone the behavior tree onto any of the game clients as it’ll be running in server memory. The only messages sent over network should be the action outcome (aka method calls with args to game components) e.g. move towards player, attack player X. Right?

It seems like a hassle to reconcile behavior trees if they ran on both client and server. Is there a reason I’d want one game agent’s behavior tree running on the game server AND n game clients?

sly grove
fickle tinsel
sly grove
#

(using the l4d example)

#

But of course when you do prediction you also need to do reconciliation logic and that gets very complicated very quickly

fickle tinsel
#

Appreciate being able to discuss. I’m just thinking.

You might be right that players will notice the round trip. I just don’t know.

If they do and it feels wrong/off, then it seems worth it to have the tree also running on the game clients.

#

I’ll have to AB test it with something basic to see if some play testers notice.

I will say this: another benefit would be players on slower connections would probably have a better experience, right?

It’s just… reconciling is quite the art isn’t it? E.g. a fallback node using randomness to choose a child node would be inconsistent across all the tree sims for one game agent. I winder if there’s a way of getting deterministic randomness across the sims; can I seed a random with the same seed?

Multiplayer is definitely tricky..

plush hare
# fickle tinsel It’s kind of like left for dead, if you’re familiar. Yea I’m trying to think if...

other players and AI are typically never predicted by the local player unless it's very physics heavy. eg: in rocket league the local player is predicting other players and the ball since the premise of the game involves smashing networked physics entities into each other. this isn't perfect at all, and if you do your googling, you'll see a lot of pissed off people complaining about going through the ball, other players teleporting after collisions etc.

#

if the AI movement gets mispredicted on the client and your player shoots him in the head, the kill will fail and you'll get an ugly correction and an angry player

#

where as properly implemented lag compensation and entity interpolation, a headshot will always be a headshot unless you're enduring heavy packet loss (or if you die on the server before your packets reach the server). the movement of said entity will also be smooth as butter since the states are held in an interpolation buffer to account for bad network conditions. both have their pros and cons but typically you're not gonna want to predict that. especially in a fast paced shooter.

#

to answer your question nobody is going to notice a <100ms response. upwards of 200-300+ will be noticeable though. most (if not all) modern AAA online shooters use entity interpolation and lag compensation.

earnest canopy
#

hey there how can i modify meshes in an ecs system

brave cairn
flint sage
scenic forge
#

For init only setter? Works for me and I haven't seen anything wrong with it.

#

Keep in mind this is just a compiler attribute, it has zero effect on runtime code.

#

Compiler simply looks for its existence and then prevent you from reassigning after init by emitting a compiler error.

flint sage
#

Interesting

#

It's a bit weird that Unity wouldn't just include it if it works in all cases

scenic forge
#

I'm guessing they rather focusing on effort migrating to Core rather than patching random things up, although it would be really nice since this is like literally a few lines of code for gaining access to init only setters and records which are two very nice C# features.

#

On that note, a lot of features being simply compiler checks/down leveling is one of the things I really like about C#. It's why things like PolySharp is possible.

flint sage
#

Yeah it's cool, just kind of sus imo

spare cargo
#

I want to instantiate a prefab that connects to an already existing one. At the top of the hierarchy, I have a simple object with a BoxCollider the size of the prefab itself. Is there a way I can get a reference to the topmost object - and that object only - without iterating through its children?

#

For context I'm trying to instantiate rooms that connect to one another, like a dungeon crawler. For each room added, I want to check if the BoxCollider of the next room will intersect with any existing rooms

stuck plinth
#

when you say get a reference to the topmost object, what do you mean? in what context?

#

where would you have to iterate through the children?

spare cargo
#

I'm trying to get a reference to the topmost parent of the hierarchy while excluding all other objects. Just wondering if there's a way to do this without iterating through all of the object's children and removing them

#

Essentially I want to instantiate just the topmost parent and nothing else

stuck plinth
#

you mean the topmost object of the prefab being instantiated, or the object that will become its parent?

spare cargo
#

Just the topmost object of the prefab being instantiated :3

stuck plinth
#

how are you instantiating it if you don't already have a reference to that 🤔

spare cargo
#

I do have a reference to the prefab itself, but am wondering how I can just instantiate the top most object and nothing else

stuck plinth
#

why would you have the other objects in the prefab if you're not instantating them?

spare cargo
#

when you get the bounds of a collider through collider.bounds.size on an uninstantiated object, it returns (0,0,0) - so my thought was to just instantiate the topmost object, grab and check the collider bounds, then instantiate the full prefab if it doesn't intersect with anything

#

Was also thinking of just using collider.size but I'd still have to create a collider to test if it intersects anyway

stuck plinth
#

that's in world space and it's not in the world so that makes sense, but you could just do a box cast using the center and size properties?

#

box overlap not box cast i guess

spare cargo
#

Ohgh that's a much better idea. i should not work this late

#

thank you!

fickle tinsel
# plush hare if the AI movement gets mispredicted on the client and your player shoots him in...

I think this is the crux of why reconciliation is an art. Given an inconsistency like what you say, it’s up to the developer to decide what happens.

E.g. in an online shooter given player X headshots player Y on X simulation, but player Y had actually run behind a corner on Y simulation, the game devs can say “we favor the shooter’s simulation” and resolve that the headshot happened. Also how in many games two people can headshot each other.

That’s also why I’d rather not have to decide what behaviors have to be reconciled and let the server be the authority.

timber flame
#

Can I create these type of shadows using light2d in urp?
I want runtime shadows, clearly they should change at runtime, I mean the direction and length

#

Light2d generally can generate shadows like below

serene oxide
#

Someone here knows how to make the login session not to stay inside the files of the game when I make a version so my account is not there for another user?

long ivy
#

you're going to need to provide a lot more detail than that

upbeat path
upbeat path
#

I presume you are talking about your user id/password to a service are you not

serene oxide
#

@upbeat path i send you dm so we dont flood the channel

upbeat path
#

no

#

@serene oxide Will you please stop DMing me before I report you to the moderators

serene oxide
#

wtf why? im just asking you how to solve it lol @upbeat path

upbeat path
#

<@&502884371011731486>

frozen imp
thorn flintBOT
#

dynoSuccess diegogb has been warned.

worldly pecan
#

This may be asking for much but does anyone know anyway to allow for CPU-side threaded/asynchronous modification of multiple sections in a compute/graphics buffer? For instance, ComputeBuffer.BeginWrite() allows for one-time CPU-side writing to one section of a GPU buffer followed by an .EndWrite(), but you can't beginWrite before ending the previous write operation.

I am able to allocate the sections to copy synchronously on the main thread(so I can guarantee each section is separate) but want to be able to actually copy the contents in several async threads. I'm willing to write my own unsafe buffer access logic to do so, is something like this possible?

brave cairn
worldly pecan
# brave cairn With BeginWrite you will get NativeArray. Make a Job with IJobFor interface (htt...

That's not exactly what I mean. When you call EndWrite you have to specify the number of things you changed, which is calculated linearly from the offset you begin write from. However, I am editing multiple non-continuous regions of an extremely large compute buffer. What I'm searching for is starting multiple write operations simultaneously and then being able to end each one with an instance of the write task or smthing.

brave cairn
#

You have two options here:

  • Work with whole buffer memory. "The returned native array points directly to GPU memory if possible" documentation says. Update necessary portions in a preferable way. For EndWrite call specify full buffer count. As long as you work directly with GPU memory there is no overhead (and copying) at all at EndWrite.
  • Make own "shadow" memory copy for compute buffer data. Work with it by recoring changed portions. When data is ready, make several ComputeBuffer.SetData calls with proper size and offsets to update only changed parts.
worldly pecan
untold moth
# worldly pecan Thanks, I'm currently doing the second option. I have some async tasks that read...

I don't see how that would be possible. I don't think the GPU has access to disk drives or the ability to interpret the data correctly from them. There would probably need to be considerable changes both to the GPU and the computer architecture in general for something like that to work.

Or so I was gonna say, but then I googled and found about DirectStorage technology in DX12, that apparently streamlines the loading process from disk into the GPU, only using RAM temporarily. It does require compatible hardware though, so what I said above is not wrong.

worldly pecan
cinder dirge
#

is there anyway to create a button in world in scene for editor ?

cinder dirge
#

thanks so much

lilac lantern
#

It's in the editor namespace so make sure you account for that

fickle tinsel
#

How do people handle secret values that works for local and production? I tried envvars but can’t find a good development story (more later).

For some reason when I’m running my game in the Unity editor I can’t write envvars via my developer tool, which seems insane to me. If I read the envvar right after I write it, it’s undefined for some absolutely mysterious reason. The production Linux server build has no issues reading passed in envvars.

Using envvars in this way would allow me not to make development into a special case. That said, any advice on how to pass on secrets that work for local and prod?

#

Ideally I don’t want these secret values in any serializable fields because the repo is public, and I don’t want to accidentally publish the secrets on a git push.

sage radish
sage radish
fickle tinsel
fickle tinsel
# sage radish https://discord.com/channels/489222168727519232/885300730104250418/1237779792015...

I ideally want to not make local a special case. Can you see why using player/editor prefs would mean my game software code would have to handle local and prod differently?

The cool thing about my envvar trick (if it worked) is that my game software code would’ve only had to know “I pull in secrets via envvar” and that would’ve worked in the unity editor and production. That’s the kind of solution I’m hoping for, if that makes any sense?

sage radish
# fickle tinsel I ideally want to not make local a special case. Can you see why using player/ed...

I use a dependency injection pattern to solve this. If some class needs a secret to function, have it part of the constructor. How the secret is produced can be different for local and prod, but it only needs to be different in one place.
Or just make a static method somewhere for reading environment variables which wraps around Environment.GetEnvironmentVariable, except it has a #if UNITY_EDITOR which reads it from somewhere else instead.

#

But the dependency injection method is preferred for making your classes easily testable by themselves, without needing to modify the environment to suit them.

fickle tinsel
#

Ignoring the DI & testable comments (preaching to the choir :), you do bring up a good point that wrapping reading the secret value in the UNITY_EDITOR directive like that is probably the best way to minimize deviation in game software code. Cool, moving forward.

nimble kite
#

I'm currently trying to use the Microsoft.Speech.Recognition namespace, but it seems like Unity's version of mscorlib.dll is outdated and doesn't have a method called from the namespace, so I can't use it. Does anyone know if it's possible to update mscorlib.dll and if so, how?

upbeat path
nimble kite
#

It's .Net Framework v3.5

upbeat path
#

too old, you need .Net 4.5 or above up to 4.7.2

deep jasper
#

What's the most proper way to make a multiplayer physics/navmeshing?
Max players amount is 4, but world itself is large, and mostly unloaded(due to chunking system)
In minecraft it's all done by server, but game has blocks instead of meshes, and custom navigation on top, and unity provides own navmesh and own physics
and well, meshes have thousands of verticies, so i probably need some API or just use what unity provides like NetCode for GameObjects/Entities
But that means that host player is also a server, and all collisions and AI stuff would be calculated on his machine

worldly pecan
# deep jasper What's the most proper way to make a multiplayer physics/navmeshing? Max players...

If you're talking about the built-in navmesh, it is not very compatible with chunk loading because it is calculated per-chunk and cannot connect between chunks(that's unless they've updated the system). You're probably better off building your own nav-algorithm.

Just guessing, but having all physics calculations being done on client side is probably easier and a good starting point, but may be more vulnerable to client-side hacking. Eventually you would want everything to be done on the host player unless you trust your userbase to not cheat.

deep jasper
#

I mean it's just a coop 4players openworld game

#

one player starts server, 3 guys connect and then all 4 get tossed to the actual game

#

so i don't think there would be cheating

#

but still, the synchronization is what should be prioritized ig

fickle tinsel
#

I prefer server authoritative; I also prefer server client model over peer to peer. Sounds like you do too?

If your game is largely physics based, run physics on all 5 simulations (4 players + game server) but allow server to correct the game clients if they mispredict.

A game server only needs to “render” the nav mesh that’s around players; to save resources, you can disable nav meshes that aren’t relevant to a particular piece of the level.

deep jasper
#

Well, my game is mostly static, but there are NPC which walk around, and also all pickable objects can be pushed around with players' bodies(like some random axe which can be pushed from chopping block, moved to the edge of the mounatin and then launched with a spell explosion)

#

and well, npc's might turn to lootable ragdolls on death

deep jasper
#

so well, i think that packets should mostly update physical objects' positions, and player coords/states/animations

#

and sometimes damage/death/ragdoll-turn/item pick-up

#

idk if this system will be compatible with combat tho

#

mmorpgs are doing combat quite well

#

but idk how they achieve it

twilit grove
#

is this really an unnecessary assignment?

thin mesa
#

yes because you don't use that variable after assigning it

#

also not an advanced question

austere jewel
#

To be clear, + in a delegate returns a new instance, so despite it being a reference type it's not modifying it

robust nexus
hushed basin
#

in DOTS what is the best way to hook a BufferLookup into the job dependency system? i have a job in system A that modifies a bunch of elements in a buffer. a second job in system B needs to do an entity lookup and uses these values. both systems need rw access. what am i missing?

#

as it is, i get errors that both are trying to access the same buffer before calling Complete(). there should be a way to do with better than calling Complete() right?

#

i think i understand. if i am understanding correctly, one system isn't using a job, its running on main thread which would bypass the dependency system

gusty kernel
#

I am putting a hexagon onto a mesh that is itself also a grid of hexagons. and I get these serrated edges (left) whenever it transitions to a new row, while other edges are clean (right). I'm sure there is an analogue to this when drawing polygons in regular square grids, but I'm not sure what the fix would be.
Here is my code for checking whether a cell is within the hexagon:

private bool PointInHexagon(float x, float z)
{
    int w = widthCells;
    int h = heightCells;

    // Convert x and z to be between 0 and 1
    x = x / (w - 1);
    z = z / (h - 1);

    // Translate point to be relative to the center of the hexagon and normalize
    x = Mathf.Abs(x - 0.5f);
    z = Mathf.Abs(z - 0.5f);

    // Hexagon constants
    float a = 0.5f;
    float b = Mathf.Sqrt(3) / 2f;


    return a * z + b * x <= a * b;
}
gusty kernel
#

Ended up finding another method by just calculating the distance to each cell from the center by traversing the grid

short junco
#

Hey guys i am getting Failed to enumerate registry keys, error code: 259 output in my code , shortly trying to get all subKeys of desired upper regedit key.

Any idea ?

private static UIntPtr HKEY_CURRENT_USER = new UIntPtr(0x80000001u);
private static uint KEY_READ = 0x20019;

[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern int RegOpenKeyEx(UIntPtr hKey, string subKey, uint options, uint samDesired, out IntPtr phkResult);

[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern int RegQueryValueEx(IntPtr hKey, string lpValueName, int lpReserved, out uint lpType, StringBuilder lpData, ref uint lpcbData);

[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern int RegCloseKey(IntPtr hKey);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int RegEnumKeyEx(IntPtr hKey,uint dwIndex,StringBuilder lpName,ref uint lpcbName,IntPtr lpReserved,IntPtr lpClass,IntPtr lpcbClass,IntPtr lpftLastWriteTime);
    {
        GetSubKeys("SOFTWARE\\Unity\\UnityEditor\\DefaultCompany\\DefaultProject");
    }
#
    public void GetSubKeys(string parentKey)
    {
        IntPtr hKey;
        int result = RegOpenKeyEx(HKEY_CURRENT_USER, parentKey, 0, 0x20019, out hKey);

        if (result == 0)
        {
            Debug.Log("Key Open Success: " + parentKey);
            uint index = 0;
            StringBuilder subKeyName = new StringBuilder(1024);
            uint subKeyNameLength = 1024;

            while (true)
            {
                int enumResult = RegEnumKeyEx(hKey, index, subKeyName, ref subKeyNameLength, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                if (enumResult == 0)
                {
                    Debug.Log("Subkey: " + subKeyName.ToString());
                    index++;
                    subKeyNameLength = 1024;
                    subKeyName.Clear();
                }
                else if (enumResult == 234)
                {
                    break;
                }
                else
                {
                    Debug.LogError("Failed to enumerate registry keys, error code: " + enumResult);
                    break;
                }
            }

            RegCloseKey(hKey);
        }
        else
        {
            Debug.LogError("Key Open Error: " + parentKey);
        }
    }
flint sage
short junco
#

But when i check in regedit there is 3 entry like 🤔 @flint sage

flint sage
#

else if (enumResult == 234)
seems wrong by the way

#

Check the error code says there's more data

short junco
#

Thanks @flint sage i will check the status codes again

timber flame
#

How can I find a valid point in nav mesh with some range?
NavMesh.SamplePosition, is it OK?
I want to find a valid random point in specific range from a character
Valid point means the character can move and reach it

fast prawn
#

is this possible?
3 planes, with z of 0,1,2
0 - is a green plane
1 - is an orange plane
2 - is a see through plane that makes 1 see through if they overlap and doesn't affect 0

flint sage
#

I'd imagine it's possible if 2 renders to a stencils, then 1 checks if the stencil is there and if so, doesn't render

fast prawn
lofty solstice
#

is there any way to garbage collect System.Reflection data? According to Unity docs it is cached internally, and I would like it to be yeeted out of existence once I've done my thing with it

lofty solstice
#

To minimize the garbage collector overhead, avoid methods such as Assembly.GetTypes and Type.GetMethods() in your application, which create a lot of C# reflection objects at runtime. Instead, you should scan assemblies in the Editor for the required data and serialize and/or codegen it for use at runtime.```
regal olive
#

We need game developers for a game called "Mortal Company" on the playstore made by unity, you should be experienced with coding in unity, you sadly won't be paid yet until the game gets famous.

dm me for more information

lofty solstice
#

wrong channel buddy

upbeat path
#

Cant do that, however you can mitigate the GC overhead a little by keeping all of your reflection calls together and issuing them as soon as possible at game startup

lofty solstice
#

That's fine - was hoping there was a secret way maybe, like inside of using scope, but I guess its not marked as IDisposable in the first place

upbeat path
flint sage
#

You might be able to use reflection to clear the dictionary

#

Haven't really looked into it though

stuck plinth
#

i guess that overhead only applies while during GC collection though? i don't think the unity GC does much work in the background, so during gameplay you would generally be avoiding that anyway

flint sage
#

For il2cpp though, I doubt you can do anything

#

Also they're likely promoted to whatever gc level is not scanned often, so the impact is not that big

upbeat path
stuck plinth
#

i don't think unity's GC does any relocation does it?

upbeat path
#

yes it does

#

there would be no point to it otherwise

stuck plinth
stuck plinth
#

oh cool, but it says it only does it during collection, so the point is if you don't run GC.Collect a lot during gameplay, you probably won't run into this overhead much?

upbeat path
#

but the collection process runs every time you do an allocation which cannot be satisfied and/or periodically

stuck plinth
#

hang on, that text you pasted is from the .NET docs, that's not the same GC as unity

upbeat path
#

yes it is, Unity uses the Mono GC which is the same as the .Net GC

stuck plinth
#

unity uses the boehm GC

#

it's not running on .NET at all at runtime

upbeat path
#

from the doc you posted

upbeat path
stuck plinth
#

i'm just reading the unity docs, it says right there it uses boehm 🤔

#

idk how it works in a mono build, but at least if you build to IL2CPP, it's not like there's a .NET runtime running as well somewhere in your game

upbeat path
flint sage
#

You're not running il either when using il2cpp

stuck plinth
#

yeah, it boils down to c++, C# is basically a fancy template for writing C++ code in unity lol

flint sage
#

Where the IL comes from doesn't matter at all, I can hand write IL, put it through il2cpp and it'll do GC operations on my objects just as fine

stuck plinth
#

right, you can use boehm GC with normal C++ code too, if you look at generated IL2CPP that's all it's doing

upbeat path
#

the point I'm making is it's using the Mono .Net IL to create the cpp and thus the .exe so what is in the Mono Il ends up being run, whether that is a .Net envirnment or not

stuck plinth
#

there's no GC inherent to C# the language though, you can run it without a GC if you really want to

flint sage
#

Are you tlaking about the (basically redundant) mono runtime target?

#

Also it's running a customized roslyn compiler to generate the IL

upbeat path
flint sage
#

So what is generated has very little to do with mono

flint sage
flint sage
#

After a build obviously

upbeat path
#

from latest Unity LTS

flint sage
#

Yes it's running the mono runtime in editor

stuck plinth
#

unity uses the mono libraries, and i guess it embeds mono in the player in a mono build, but there's no mono runtime in an il2cpp build and according to the docs they use boehm even in mono builds

upbeat path
#

well what do you thing a build does? Have you ever looked at one?

upbeat path
flint sage
#

That's literally a mono build dude

stuck plinth
#

the mono libraries are used in the build, either directly or by compiling them to C++, but the GC isn't part of the library, it's in the runtime itself

#

you don't compile the GC into your game, it's in unity already

flint sage
#

il2cpp builds don't contain a managed folder

upbeat path
#

yes, and in A IL2CPP build all of those dll's are converted into cpp and put into one .exe, there is no difference to the runtime code

flint sage
#

Right, this conversation is clearly not going anywhere, so I'm going to bow out

mystic widget
#

Is it possible to record a code driven animation in Unity? I have an pose created through inverse kinematics that I want to export as an animation but when I hit record it puts the character in T-pose

hoary plinth
#

I'm having some problems using a render texture in to display another camera's output in a 2d game. Is there a compatibility issue with using render textures to output a second camera's view in 2d? The tutorials I've been finding have all been done in a 3d project rather than 2d.

hoary plinth
#

I think the problem is that it by default sets up the material for a 3d environment using lighting and doesn't use 2D sorting order. I created a custom Shader from a few sources that is rendering the texture now. Remaining issue I think is related to the UVs of my custom mesh.

fickle tinsel
lofty solstice
#

yeah no GC collect doesnt work on reflection objects

edgy zealot
#

Sorry if its not advanced enough lol ,

How do i assign an event to a public void in a script in my unity project so that other scripts can subscribe to the event?

#

What im wanting to do is intead of hardcoding interactions between a script and another one i want to be able to use an event that one can listen to to know when a specific method is called from the other

devout hare
edgy zealot
devout hare
#

I'm telling you I don't call methods "voids"

edgy zealot
#

im just trying to explain my problem in the simplest of terms. But thank you for the tutorial.

I mean thats what a method in unity is though... To each their own i guess.

devout hare
#

No it's not

thin mesa
edgy zealot
#

true

#

my apologies

devout hare
#

It's very common for methods to not return anything in basic Unity scripts but that's only in the very basic level

edgy zealot
#

yeah i dont know what i was thinking lol

#

Thanks for the tutorial though i think i understand how to do it , I really need to start using delegates more... didn't even know you could encapsulate methods like that

limber snow
#

HI there 😄 one question, if im loading addressables scene using async, should i make before the occlusion of all scene together and the navigation map?

sage radish
upbeat path
#

do not cross post

frail willow
upbeat path
#

yes

frail willow
#

thank you

#

done

upbeat path
#

also this is a code channel, so posts should include the code involved. How can we know what you are doing on the basis of a screenshot?

frail willow
#

I see.

limber snow
torpid smelt
#

Alright, more of a math thing, but I'm having trouble wrapping my head around rotations.

I'm currently trying to make an object follow another object's rotation, however, only the difference of when it starts

Which I have working. Kinda. my code records the initial rotation of both the controller object rotation and target object rotation, and applies the difference between the current controller rotation and the initial controller location to the target's initial rotation. ae:

Quaternion currentrot = caller.ownerController.transform.rotation;


        Quaternion initialDifference = Quaternion.Inverse(initialObjectRot) * initialControllerRot;

        rotDifference = Quaternion.Inverse(initialControllerRot) * currentrot;

        if (toModify == null) {return; }

        rotDifference = initialDifference * rotDifference;


        targetRot = initialObjectRot * rotDifference;```

This works, but only if the normals are about the same direction, which isn't always the case. Any attempts I've made to solve this via offset (ae, add an offset to account for the difference between the initial controller dir & the initial object dir) just make it face the same direction as the controller instead of applying the same "relative" rotation.

Any suggestions?

I've tried using Quaternion.FromToRotation to a similarly dissapointing (arguably moreso) result:

```java
Vector3 initialControllerForward = initialControllerRot * Vector3.forward;

        Vector3 initialControllerUp = initialControllerRot * Vector3.up;


        Vector3 InitialObjectForward = initialObjectRot * Vector3.forward;

        Vector3 InitialObjectUp = initialObjectRot * Vector3.up;

        Vector3 ForwardDiff = (InitialObjectForward - initialControllerForward).normalized;
        Vector3 UpDiff = (InitialObjectUp - initialControllerUp).normalized;


        Quaternion currentControllerRot = caller.ownerController.transform.rotation;

        Vector3 targetForward = currentControllerRot * ForwardDiff;
        Vector3 targetUp = currentControllerRot * UpDiff;

        targetRot = initialObjectRot;
        targetRot *= Quaternion.FromToRotation(UpDiff, targetUp);
        targetRot *= Quaternion.FromToRotation(ForwardDiff, targetForward);
        ```
#

I feel like it's a one line fix for either, I'm just not comfortable enough w/ Trig yet lol

torpid smelt
#

nvm lol I just needed to inverse the difference and make the target rot the inverse of the diff applied to the current rot

pallid herald
#

heya, im trying to recreate this woodcarving effect by Daniel Beauchamp here: https://twitter.com/pushmatrix/status/1511331419896913920
but im running into a little bit of trouble at creating the shavings mesh, it works fine when the knife moves in the same direction as the stick, but when its at an angle, it either gets all weird and jank or really thin, and im really stumped as to how to get it working, any ideas?

untold moth
atomic vapor
#

I'm having a lot of issue trying to build for WebGL.

Fatal error in Unity CIL Linker
System.NullReferenceException: Object reference not set to an instance of an object.
   at Unity.Linker.Analytics.AnalyticsService.RecognizedReflectionAccessPattern(IMemberDefinition source, Instruction sourceInstruction, IMetadataTokenProvider accessedItem)
   at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.MarkTypeForDynamicallyAccessedMembers(ReflectionPatternContext& reflectionContext, TypeDefinition typeDefinition, DynamicallyAccessedMemberTypes requiredMemberTypes)
   at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.RequireDynamicallyAccessedMembers(ReflectionPatternContext& reflectionContext, DynamicallyAccessedMemberTypes requiredMemberTypes, ValueNode value, IMetadataTokenProvider targetContext)
   at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.ProcessGenericArgumentDataFlow(GenericParameter genericParameter, TypeReference genericArgument, IMemberDefinition source)
   at Mono.Linker.Steps.MarkStep.MarkGenericArgumentConstructors(IGenericInstance instance, IMemberDefinition sourceLocationMember)
   at Mono.Linker.Steps.MarkStep.MarkGenericArguments(IGenericInstance instance, IMemberDefinition sourceLocationMember)
   at Mono.Linker.Steps.MarkStep.GetOriginalType(TypeReference type, DependencyInfo reason, IMemberDefinition sourceLocationMember)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
   at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementation(InterfaceImplementation iface, TypeDefinition type)
   at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementations(TypeDefinition type)
   at Mono.Linker.Steps.MarkStep.MarkRequirementsForInstantiatedTypes(TypeDefinition type)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
   at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
   at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
   at Unity.Linker.Steps.UnityMarkStep.InitializeAssembly(AssemblyDefinition assembly)
   at Mono.Linker.Steps.MarkStep.Initialize()
   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
   at Unity.Linker.Steps.UnityMarkStep.Process(LinkContext context)
   at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
   at Mono.Linker.Pipeline.Process(LinkContext context)
   at Unity.Linker.UnityDriver.UnityRun(Boolean noProfilerAllowed, ILogger customLogger)
   at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(ILogger customLogger, Boolean noProfilerAllowed)
   at Unity.Linker.UnityDriver.RunDriver()
UnityEditor.GenericMenu:CatchMenu (object,string[],int)```

Trying to implement SignalR using this guide here: https://prog.world/connecting-signalr-to-unity/
#

Using linker file still seems to give issues

regal olive
#

Help optimise this LogHandler impl

worthy vapor
#

hello, this my seem like a stupid question but i'm genuinely interested in the answer
Do customEditor scripts or in-editor tools get compiled or affect the build in any way (for example bigger built game) ?

sly grove
#

as long as you porperly put them in an Editor folder or in an Assembly that is editor-only targetted

worthy vapor
#

and what about OnDrawGizmos or OnValidate of MonoBehaviours ?
Does it get compiled ?

sage radish
stuck plinth
#

i guess i'd expect them to be likely to be stripped out of the final build, since they would have no callers in a player, but i haven't tested that

sly grove
sage radish
stuck plinth
oak sable
grave raft
#

How do i get rangelines on sight

#

Example:

sly grove
grave raft
#

Here yes, i need to generate one in runtime when i switch bullets

grave raft
#

Thank you

warped ibex
#

Anyone knows how to use the NCalc C# package with unity?

rapid moon
#

hi

sly grove
warped ibex
light citrus
#

okay people, I think I need professional help becouse I can't find a solution anywhere... I'm trying to create a replay feature in the game, something like, everytime you die, but I also want them to be able to download the MP4 of the replay... how the hell do I do that? I've been looking everywhere, I found ways to record in editor and export in mp4, but I can't find a single tutorial in how to do this "IN GAME"

sly grove
#

Certainly it would be prohibitive to record video in MP4 format all the time for all your players, so likely you'd want to do more of a keyframe-based replay system. But now you need to be recording keyframes for basically everything in your game that's visible all the time, and store them in some kind of buffer.

When you want to do a download as an MP4 it would have to trigger a resimulation of those keyframes and render the game and record it all to video... quite a demanding task in terms of compute resources.

light citrus
#

my only job is making the capture system and making sure we can get a mp4 out of that

#

at least the only part that is missing on my part

sly grove
#

seems like a huge task

light citrus
#

well, the only part I need is to get a recording working, that has a defined start and end

#

showcase him, and then turn into a mp4

warped ibex
#

Maybe NCalc is already included in unity or something..

sly grove
sand abyss
warped ibex
sly grove
warped ibex
#

Btw do I have to add "Using NCalc;" on top of my scripts?

sly grove
warped ibex
sly grove
#

As always, you can use using directives to eliminate the need to type out the fully qualified name of a type.

#

they are never strictly necessary

warped ibex
#

Alright, wanted to make sure that thats still the case for packages gotten from a dll

#

First time having to use C# libraries like NCalc lmao

old pike
#

im not 100% sure if this is the question to ask here but

#

im having an issue with finite state machine

#

i followed the official unity tutorial and its not working

#

heres the tutorial

#
Unity Learn

In this project we start writing the pursue and attack states to add to the NPCs behaviour. Next, we will complete the code for getting the NPC to pursue and attack the player.

#

anyone know whats wrong?

#

my guy does not switch states

#

he just

#

patrols

#

only

flint sage
#
    {
        stage = Event.UPDATE;
    }```
Probably this, Unity probably calls that every frame
old pike
#

ah, so remove that?

#

i ended up removing it

#

he broke lol

#

added it back

#

still broke lol

clever widget
#

Hi guys, I'm getting this error in Xcode when I try to make a build using Unity 2022.3.25:
Undefined symbol: __HasVibrator
It was not there in 2020. Has anybody else faced this issue before?

fiery garnet
#

Visual scripting any state causes 2 states to run simultaneously, is there any fix 🤔

#

Version 1.8.0

obsidian glade
# old pike anyone know whats wrong?

just reading through it seems like there might be some confusion about Process & Update, as Navi mentioned. I'd perhaps consider changing what you want to be your manual "do this every frame while it's in stage UPDATE" call to Tick() instead, and make it clear what is being called by Unity automatically and what is your logic

I'd also expect your logic to move the stage along, but I don't see any of the Enter() calls pushing the stage to UPDATE. Adding some debug lines to print which stage you're actually processing at any given time will probably make it clear where the difference is between what you expect and what's actually happening

rigid shale
#

Hey Guys, currently I try to change some Outline Settings on runtime via C# and Precreated OutlinePresets. ut after some time - I have no idea how it works. Currenlty I tried something like this:

public class ChangeOutlineViaPreset : MonoBehaviour
{
    public ListItem ListItem;
    public UnityEditor.Presets.Preset Green;
    public Object OOutline;

    // Start is called before the first frame update
    void Start()
    {
        if (ListItem.name.Contains("*green*"))
        {
            Debug.Log(CopyObjectSerialization(Green, OOutline));
        }
    }

    // This method uses a Preset to copy the serialized values from the source to the target and return true if the copy succeed.
    public static bool CopyObjectSerialization(Object source, Object target)
    {
        UnityEditor.Presets.Preset preset = new UnityEditor.Presets.Preset(source);
        return preset.ApplyTo(target);
    }
}
swift orchid
#

Can I map serverless different logins(Facebook, Apple, GooglePlay) to one Account in Unity.CloudSave ?

pallid glacier
#

Hi, i've made a post in the unity forum, i'm sending the message here also to try reaching more people, in short i have the following issues :

  • Long building process
  • Maximum sampler issue with URP
  • Graddle keystore issue

https://forum.unity.com/threads/multiple-issues-and-question-of-compiling-vr-game.1596960/

half lintel
timber flame
#

What do you think about AI approaches in diplomacy strategy games?
I prefer HTN + utility over GOAP, what is you opinion?
The player has some neighboring countries. They can be friend/ally or enemy. The player can trade, invade, make sanction, change policy, customs, tariff, entry permit, etc.
and is there any framework/tool for HTN in unity like planner or I should implement it myself from scratch?

late thorn
dusty wigeon
timber flame
dusty wigeon
pallid herald
# untold moth You'll need to provide more details on the issues. Start with one issue and expl...

ofc, right now every frame i check whether each vertex has been cut by the knife, and if it does i move it do be flush with the knife,
i also want to create a shavings mesh out of the hit vertices, from the one thats been hit the closest to the top of the blade and one closest to the bottom something like this:
however, the problem is that most frames only one vertex gets hit, and what i'd like to do is somehow get the rows of vertices in realtime to i can create the mesh, so i'd like to know if anyone has an idea as to implement this i'd love to hear <3.

#

i've tried clumping them into groups, but it all turns out really jank

untold moth
#

How are you creating the mesh? Are you sorting the vertices every frame before creating it?@pallid herald

shut hedge
#

If I have a monobehaviour or scriptableObject, which has a fields which are serializable classes, I can just edit them inline. However, can I also have them as null? So basically the user should be able to decide if he wants to populate that member or not

#

I see how I could do that with an additional boolean field

sly grove
#

Nor nullable types

shut hedge
#

all classes are nullable or not?

#

but basically unity just gets rid of that?

#

ok then a boolean field it is

sly grove
#

If you're mostly interested in the inspector you'd use a custom inspector or property drawer

shut hedge
#

I think I'll just have the boolean field there and the other field visible always

#

I don't know if it just seems like it or if its true, but the inspector stuff seems to be quite lengthy for relatively simple things

#

seems to be done rather for proper extensions than for quick eye-candy changes

sly grove
#

Use NaughtyAttributes you can do a lot with a little

shut hedge
deep jasper
#

Can anybody explain how RenderMeshIndirect works

#

and what do i need to make it spawn several meshes for me in some small bounds

echo bloom
#

Why my c++ not work:

print("hello world");
###############
#me build differenet#
###############```
#

How to youse turtle in c+#

deep jasper
#

is that related to my question?

echo bloom
#

Yes

deep jasper
#

Well, im not saying my code is not working

echo bloom
#

It's the solution

deep jasper
#

there is no code at all rn, only the declaration part

echo bloom
#

Ok but my solution work

deep jasper
#

sure

#

but don't you know how RenderMeshIndirect works7

echo bloom
#

I do

deep jasper
#

can you explain it a bit

echo bloom
#

Use tkinter.utilize.unityessentials in your first line of first c++ script

deep jasper
#

what

#

it's c# uk

upbeat path
#

<@&502884371011731486> spam

gloomy hollow
upbeat path
gloomy hollow
deep jasper
#

so well, I started with this

void Update()
{
    Graphics.RenderMeshIndirect(rparams, mesh, buff);
}```
where
```csharp
public Material material;
public Mesh mesh;
private RenderParams rparams;
private GraphicsBuffer buff;

void Start()
{
    rparams = new RenderParams(material);
    // mesh and material are dragged to fields in Unity Editor
}

And my question is about how do i use buffer and what's it's purpose here
I read that GraphicsBuffer is used to store data inside the GPU, and that's the only thing i know rn

upbeat path
sage radish
# deep jasper and what do i need to make it spawn several meshes for me in some small bounds

RenderMeshIndirect is a more complicated version of RenderMeshInstanced, where instead of feeding in the number of instances directly to the method, you do it indirectly through a GraphicsBuffer, which can be populated by a shader. But another reason people use the Indirect version is because RenderMeshInstanced has a max limit of 1023 instances, which the Indirect version doesn't have. Is that maybe why you chose the Indirect version?

deep jasper
#

yeah, my goal is to draw 100k grass meshes faster than rn

#

using just the RenderMeshInstanced

#

there are 60k meshes with around 60fps

#

it feels like a low amount

#

guys draw millions sometimes and even apply physics and still have more than 200fps

#

idk if that's because of alpha clipping or smth, but mesh has 16 verts in total(4 planes crossed making a star shape)

sage radish
# deep jasper there are 60k meshes with around 60fps

RenderMeshIndirect will not speed up the GPU performance of the draw call. But it can allow you to optimize everything needed to prepare the draw call, such as moving the instance calculations to a compute shader.
But before you do anything like that, you need to identify what the problem is before you can fix it.

deep jasper
#

well, main problem is idk if everything is optimized for calling draw(the mesh, the material, the texture, the project xD)

#

and second is the moving part

#

camera can rotate, also character can move

#

i don't really want to render everything outside of camera view + i want to apply LOD so grass far away will only have 8 verts instead of 16

sage radish
#

Frustum culling and LOD calculations are best done with a compute shader, since it's an easy problem to parallelize.

deep jasper
#

well, my last attempt brought me to 40 fps

#

instead of 60

#

with lod and culling(it was bad)

#

i mean on screen it looked properly, but performance decreased

#

so you mean compute shader can help me change a mesh from one to another based on cam distance?

#

or i would need a read/write buffer and do the mesh change in a c# script

sage radish
#

So "change a mesh" really just means choosing a different mesh when you prepare the next draw call.

deep jasper
#

alr, render several meshes, not spawn

sage radish
#

Because you will have to choose a mesh every single time for every single instance.

deep jasper
#

and change a mesh means i have a position and mesh data(mesh number) in a buffer

#

so i need to change mesh data in this struct

hollow beacon
#

Does anyone know how to configure the ExportContext in the UnityGLTF plugin so that it exports animations, because ExportOptions is now deprecated?

sage radish
deep jasper
#

so well, i start with 2 separate buffers like fullResBuffer and lodBuffer

sage radish
#

And then you would have a compute shader that will decide which buffer each grass instance will go.

deep jasper
#

then each frame i send a cam position to the compute shader and ask to place grasses in buffer1 or buffer2

sage radish
#

You can create an Append buffer for this, which acts like a list with a max size.

deep jasper
#

they just don't work for me for some reason

#

reason is i'm bad but still

#

i debugged stuff for hours trying to figure out why append buffer does some weird stuff when i read it's data

sage radish
deep jasper
#

well, as i'm thinking

#

don't i need a third buffer

#

which represents set of all positions

#

just the float3

#

from which i select grasses and send to 2 smaller append buffers

sage radish
#

How do you intend to generate the positions? Can the compute shader not do this too?

deep jasper
#

well

#

i created a GrassZone component and a visualiser for it

#

green box like collider

#

so i set the bounds for grass zone manually using object scale

#

script has a density value which just represents how many grasses are in this grass zone

#

so with current settings it's 100 grass meshes across a 300x300 plane

#

really low density

#

1 grass per 9 units or smth

sage radish
#

That sounds like something a compute shader can do. You just give the compute shader information about the plane and density, and do the same logic as the script.

#

Then you can do a Dispatch for each Grass Zone.

deep jasper
#

what about the plane geometry

#

for generating positions i used my own code which used raycasts from above

#

and added a "GrassSupport" component

#

so some objects allowed grass growth on them like old moss-covered chests

humble leaf
#

@echo bloom There is no off topic here.

humble leaf
deep jasper
#

and also since set of positions is generated once on start, it's not a big deal

#

i just run the thing while showing user a loading screen

sage radish
deep jasper
#

actually with 100k positions it runs nearly instantly

#

less than a second at least

sage radish
#

Are you using RaycastCommand?

deep jasper
#

no, just the Physics.Raycast

#

what is a RaycastCommand

#

oh i see

#

async raycast batch

#

well, i will switch to it after i'm done with grass problem

pallid herald
deep jasper
untold moth
pallid herald
#

just by order of them being hit

#

'''void AddHitsToClump()
{
Vector3[] vertices = mesh.vertices;
foreach (int hitIndex in hitIndices)
{
Vector3 vertex = vertices[hitIndex];
Vector3 knifeCoords = knifeTracker.KnifeCoord(transform.TransformPoint(vertex));
float localX = knifeCoords.y > 0 ? knifeCoords.x : -knifeCoords.x;
CurrentClump.Add(nativeVertices[hitIndex], localX);
}
lastVel = knifeTracker.KnifeVelocity;
}'''

untold moth
pallid herald
#

yaya so im wondering if anyone's got any idea as to how to sort them

#

im thinking of maybe checking the z position relative to the movement direction of the knife

untold moth
#

There're algorithms specifically for that purpose.

#

From quick google, Delaunay triangulation is one

#

That beings, said, there might be a simpler way, considering you know the orientation of the original mesh and it's vertices.

pallid herald
#

okie thx alot!

#

im just kinda new to the whole mesh generation so im not quite sure what to look for

gloomy hollow
deep jasper
# sage radish Sorry, no.
private void UpdateDensity(int density)
{
    this.density = density;

    positions.Dispose();
    fullResBuffer.Dispose();
    lodBuffer.Dispose();

    positions = new ComputeBuffer(density, 12, ComputeBufferType.Append);
    fullResBuffer = new ComputeBuffer(density, 12, ComputeBufferType.Append);
    lodBuffer = new ComputeBuffer(density, 12, ComputeBufferType.Append);

    var results = new NativeArray<RaycastHit>(density, Allocator.TempJob);
    var commands = new NativeArray<RaycastCommand>(density, Allocator.TempJob);
    for (int i = 0; i < density; i++)
    {
        Vector3 randomPoint = new(Random.Range(-transform.localScale.x / 2, transform.localScale.x / 2), 4096, Random.Range(-transform.localScale.z / 2, transform.localScale.z / 2));
        commands[i] = new RaycastCommand(transform.TransformPoint(randomPoint), Vector3.down, QueryParameters.Default, 8192);
    }
    JobHandle handle = RaycastCommand.ScheduleBatch(commands, results, density, density, default);
    handle.Complete();

    List<Vector3> coords = new();
    foreach (var hit in results)
    {
        if (hit.collider != null)
        {
            coords.Add(hit.point);
        }
    }
    positions.SetData(coords);
    results.Dispose();
    commands.Dispose();
}```
sage radish
#

Make sure you dispose of the native arrays. You can just put using in front of var results and var commands.

#

Safer to use using, in case there's an exception and the bottom isn't reached.

deep jasper
#

alr

sage radish
#

using automatically adds a try-finally block for you.

deep jasper
#

yeah i remember from java

#

commands[i] = new RaycastCommand(transform.TransformPoint(randomPoint), Vector3.down, QueryParameters.Default, 8192); this line breaks now

#

cannot modify the commands variable

sage radish
deep jasper
#

well

static dragon
#

hi

deep jasper
#

time to restructure

#

well, coded it

#

time for the compute shader

scenic forge
deep jasper
#

you mean it's some kind of downloadable wrapper stuff for native collections

#

or unity just has built-in .set() method in NativeArray class

scenic forge
#

No, just C# extension methods.

wispy rose
#

Is there a way to use the PlayerLoop class to insert something just before rendering like the native FrameEvents.OnBeforeRender? PlayerLoop.GetCurrentPlayerLoop() only seems to ever contain entries that stop just before frame rate matching. Is there a different process available for inserting into that portion of the loop?

obsidian stump
#

stevesmith whats your age.

upbeat path
obsidian stump
upbeat path
static dragon
#

steve, its cool that u are making games at that age, i hope i wil never retire and just keep doing cool stuff then

obsidian stump
#

from how long are you making games stevesmith.

upbeat path
#

I started in '77

#

So close to 50 years

static dragon
#

u r an OG

static dragon
#

cool

upbeat path
#

lots and lots, and still do, not much you would know about though

static dragon
#

hobby or full time job?

upbeat path
#

Hey, I retired long, long ago, now I only do commisions

static dragon
#

fun

upbeat path
#

I will let you into the secret of how to make money in the games industry. Don't make games, make frameworks and let others have the pain

static dragon
upbeat path
#

Little or no profit for 99.99% of indie devs

static dragon
wispy rose
# upbeat path https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnPreRender.html

Thanks, @upbeat path! Unfortunately, I am not working with MonoBehaviours in this case (ComponentSystemGroup in ECS) so I am unable to use the MonoBehaviour callbacks; although, I could probably use the Camera event and work it into the group to only update at that time. Just wish the PlayerLoop class actually covered the entire PlayerLoop. 😢

obsidian stump
#

to make a framework is not that easy i used to make games using java in my past with lengthy lines of code.

upbeat path
#

you're right, frameworks are not easy but... you get to license them to multiple clients and reap the rewards of their endeavours

#

plus they pay for support, something sorely lacking in this industry

obsidian stump
#

i think that is what godot is doing now.

#

they took brackey guy for their product advertisement and now he is doing publishing.

upbeat path
#

come on, all the children want is to make money, but they dont want to pay for anything, they expect support to be instant and also free, this is untenable

untold moth
obsidian stump
#

its not about paying anything steve but it requires lots of hardcore programming. i have been through all programming languages c,c++,java ,assembly.etc mastered them but to build a framework it requires more programmers like me.

sage radish
upbeat path
obsidian stump
#

17 years.

wispy rose
upbeat path
#

then you should know it's all about concepts. Software design and developement is an Art not a Science

obsidian stump
#

yes.

upbeat path
#

So, like any art, there are those who can and those who can't, it's innate ability, that cannot be learned

#

I play guitar and piano, I paint and draw. I will never play at the Albert hall and I sure ain't no Picasso

untold moth
untold moth
wispy rose
untold moth
#

What makes you think so?

#

It would be really weird if the editor loop was pushed in between the player loop frame update.

deep jasper
#

i can't rly use an append compute buffer as a graphics buffer for RenderMeshIndirect

sage radish
deep jasper
#

how do i create one out of my 2 current buffers with positions for lod or fullres

sage radish
#

After appending to your append buffers, you then use GraphicsBuffer.CopyCount to copy their counts to the draw call args buffer.

deep jasper
#

alr so i create a var for buffer at first

sage radish
# deep jasper

Target would be IndirectArguments. There's an example of this in the documentation page for RenderMeshIndirect.

deep jasper
#
fullResGBuffer = new GraphicsBuffer(GraphicsBuffer.Target.IndirectArguments, density, sizeof(myAss));```
#

i'll change the stride later on ig

#

when i get how many bytes element takes

sage radish
#

It's in the example in the docs.

deep jasper
#

GraphicsBuffer.IndirectDrawIndexedArgs.size

#

dis?

regal lava
#

usually you can ask marshal to do it for ya

sage radish
deep jasper
#

who's marshal

#

xD

#

so well, code looks like

void Update()
{
    if (lastDensity != density)
    {
        UpdateDensity(density);
    }
    grassCompute.SetFloats("camPosition", cam.transform.position.x, cam.transform.position.y, cam.transform.position.z);
    grassCompute.Dispatch(1, 1, 1, 1);
    GraphicsBuffer.CopyCount(fullResBuffer, fullResGBuffer, 0);
    GraphicsBuffer.CopyCount(lodBuffer, lodGBuffer, 0);
    Graphics.RenderMeshIndirect(rparams, mesh, fullResGBuffer);
    Graphics.RenderMeshIndirect(rparams, mesh, lodGBuffer);
}```
sage radish
#

You can reuse the same args buffer because you'll only be able to do one draw call at a time. So you can set it up as:

Initialization:
1. Create and initialize grass positions buffer.
2. Create fullRes and lod append buffers.
3. Create draw args buffer.
Update:
1. Clear fullRes and lod append buffer counts.
2. Dispatch compute shader to append to the append buffers.
3. Copy fullRes count to draw args buffer.
4. RenderMeshIndirect fullRes.
5. Copy lod count to draw args buffer.
6. RenderMeshIndirect lod
deep jasper
#

i don't get the Update step 1

regal lava
#

Oh, you're still on the grass thing. I was looking at Unity 6 today and they were introducing a bunch of tools like that GPU indirect culling you were looking into

sage radish
#

The append buffers will still have their counts from last frame. You have to clear them back to zero.

#

GraphicsBuffer.SetCounterValue(0)

deep jasper
#

so

 grassCompute.SetFloats("camPosition", cam.transform.position.x, cam.transform.position.y, cam.transform.position.z);
 grassCompute.Dispatch(1, 1, 1, 1);
 GraphicsBuffer.CopyCount(fullResBuffer, gBuffer, 0);
 Graphics.RenderMeshIndirect(rparams, mesh, gBuffer);
 GraphicsBuffer.CopyCount(lodBuffer, gBuffer, 0);
 Graphics.RenderMeshIndirect(rparams, mesh, gBuffer);```
#

i reuse the same gBuffer

#

first for full res and then for lod

deep jasper
#

aren't they

sage radish
#

You can use either. GraphicsBuffer is a more recent, more general version of ComputeBuffer.

deep jasper
#

so one extends another

sage radish
#

No, ComputeBuffer came first with a more specific use case. Then they made GraphicsBuffer which can represent any kind of buffer on the GPU, including what ComputeBuffer was doing.

deep jasper
#

alr i reset to 0

#

then send cam position

#

then copy count from fullres to g

#

then render

#

then copy count from lod to g

#

and render again

sage radish
#

Ok, it looks like you're not initializing the draw args buffer correctly. This is what the struct is:

public struct IndirectDrawIndexedArgs
{

      /// <summary>
      ///   <para>The number of vertex indices per instance.</para>
      /// </summary>
      public uint indexCountPerInstance { get; set; }

      /// <summary>
      ///   <para>The number of instances to render.</para>
      /// </summary>
      public uint instanceCount { get; set; }

      /// <summary>
      ///   <para>The first index to use in the index buffer of the rendering call.</para>
      /// </summary>
      public uint startIndex { get; set; }

      /// <summary>
      ///   <para>The index to add to values fetched from the index buffer.</para>
      /// </summary>
      public uint baseVertexIndex { get; set; }

      /// <summary>
      ///   <para>The first instance to render.</para>
      /// </summary>
      public uint startInstance { get; set; }
}
#

With this: GraphicsBuffer.CopyCount(fullResBuffer, gBuffer, 0);, you're copying the count of fullResBuffer to the first byte offset, which is indexCountPerInstance. That's not correct, you want to set instanceCount, which is the second argument, at byte offset 4.

#

indexCountPerInstance should be set to the triangle count of the mesh. The last three can be zero, which they are by default.

deep jasper
#

wait

#

i need to get it

#

im using 100% of my brain rn

#

sss... so

#

I can make postions, fullRes and lod buffers GraphicBuffers

#

right?

#

since graphic buffers can have type of append or structured

sage radish
#

You can.

deep jasper
#

should i?

sage radish
#

There's no performance improvement to be gained. It's just a different API to get the same thing. But you might end up in a situation where a newer method only accepts the newer GraphicsBuffer, so it's usually best to use that.

deep jasper
#

well

sage radish
#

But if you haven't run into that problem, you don't need to hurry to change it now.

deep jasper
#
private GraphicsBuffer positions, fullResBuffer, lodBuffer;


positions = new GraphicsBuffer(GraphicsBuffer.Target.Structured, density, 12);
fullResBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, density, someSize);
lodBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, density, someSize);```
deep jasper
#

problem with my knowledge and understanding

#

so well, pos buffer is just a ton of float3

#

XYZ

#

and what should fullRes and lod contain?

#

not only a position, but also a vertex count or smth

#

or i'm going in completely wrong direction

sage radish
#

Information about the mesh won't be necessary, because that's already handled by Unity. Do you have a custom shader on the grass or do you intend to use built-in shaders if possible?

#

@deep jasper It's best if you use a custom shader. Otherwise, you need to prepare the data in the specific format that Unity's shader expect them to be in, which isn't going to be the most memory efficient.

deep jasper
sage radish
deep jasper
#

urp

#

hdrp is too hard for me now

#

URP lit if you want the name of the shader

#

i can do my own less complex shader in shadergraph

#

with only alpha clipping value and texture2d input

sage radish
# deep jasper URP lit if you want the name of the shader

Ok. Shader Graph is the easiest way to make a lit shader in URP. Hand written shaders need a lot of boilerplate just to get a basic lit shader. But GPU instancing support for Shader Graph is a bit weird. I think it's possible, but there's no docs for it.
https://forum.unity.com/threads/shadergraph-instancing.1339943/

#

Some weird steps you need to take to get it work. No idea if this still works.

deep jasper
#

i never wrote a shader myself

#

except the compute

sage radish
#

I wouldn't recommend it in URP if you want lighting support.

#

So even though the Shader Graph route seems a bit weird, I would still recommend trying that first.

deep jasper
#

so i need to modify some stuff here

sage radish
#

Try following the steps in the thread I sent you. If you run into issues with that, I would suggest moving over to #archived-shaders and asking there. A lot of Shader Graph experts there who know more than me.

deep jasper
#

steps in this shader are not rly using texture tho

sage radish
#

It's only showing the steps required enable instancing support, read from a structured buffer with the right index and returning some value in a Custom Function node, which you can then use however you want in the graph.

#

For example, the Custom Function node could return the float3 position for this grass instance, which you can then add as an offset to the Object Space Position (i.e. vertex position)

deep jasper
#

what's the type of shader guy uses

sage radish
#

That's the wrong menu. Look in the Shader Graph menu.

deep jasper
#

i mean the code

#

where does he write it

sage radish
deep jasper
#

alr

#

what's this reference

#

to where

sage radish
#

I think it's created in the Blackboard, like a property.

deep jasper
#

for me it's

sage radish
deep jasper
#

well, after all

#

where does this link go

#

vertex position?

sage radish
#

Sure. It's just a hack to ensure that bit of code runs.

deep jasper
#

well, it's done

#
public class GrassZone : MonoBehaviour
{

    public Material material;
    public Mesh mesh, lodMesh;
    public int density;
    private int lastDensity = 0;
    private RenderParams rparams;
    private GraphicsBuffer positions, fullResBuffer, lodBuffer;
    private GraphicsBuffer gBuffer;
    private ComputeShader grassCompute;
    private Camera cam;

    private void Start()
    {
        UpdateDensity(density);
        rparams = new RenderParams(material);
        cam = Camera.main;
        gBuffer = new GraphicsBuffer(GraphicsBuffer.Target.IndirectArguments, density, GraphicsBuffer.IndirectDrawIndexedArgs.size);
    }

    void Update()
    {
        if (lastDensity != density)
        {
            UpdateDensity(density);
        }
        fullResBuffer.SetCounterValue(0);
        lodBuffer.SetCounterValue(0);
        grassCompute.SetFloats("camPosition", cam.transform.position.x, cam.transform.position.y, cam.transform.position.z);
        grassCompute.Dispatch(1, 1, 1, 1);
        GraphicsBuffer.CopyCount(HOW); // HOW
        Graphics.RenderMeshIndirect(rparams, mesh, gBuffer);
        GraphicsBuffer.CopyCount(HOW); // HOW
        Graphics.RenderMeshIndirect(rparams, lodMesh, gBuffer);
    }
}```
#

and that's the code which runs in the beginning

private void UpdateDensity(int density)
 {
     lastDensity = density;
     positions.Dispose();
     positions = null;
     fullResBuffer.Dispose();
     fullResBuffer = null;
     lodBuffer.Dispose();
     lodBuffer = null;
     positions = new GraphicsBuffer(GraphicsBuffer.Target.Structured, density, 12);
    // ITS PROBLEMATIC
     fullResBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, WHAT IS THE SIZE HERE, WHAT IS THE STRIDE HERE);
     lodBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Append, WHAT IS THE SIZE HERE, WHAT IS THE STRIDE HERE); 
    // I DON'T GET IT
     using var results = new NativeArray<RaycastHit>(density, Allocator.TempJob);
     var commands = new NativeArray<RaycastCommand>(density, Allocator.TempJob);
     for (int i = 0; i < density; i++)
     {
         Vector3 randomPoint = new(Random.Range(-transform.localScale.x / 2, transform.localScale.x / 2), 4096, Random.Range(-transform.localScale.z / 2, transform.localScale.z / 2));
         commands[i] = new RaycastCommand(transform.TransformPoint(randomPoint), Vector3.down, QueryParameters.Default, 8192);
     }
     JobHandle handle = RaycastCommand.ScheduleBatch(commands, results, 1, 2, default);
     handle.Complete();
     commands.Dispose();
     List<Vector3> coords = new();
     foreach (var hit in results)
     {
         if (hit.collider != null)
         {
             coords.Add(hit.point);
         }
     }
     positions.SetData(coords);
 }```
jagged fiber
#

Is there a way to get on-screen keyboard height on mobile?

deep jasper
#

Users can scale it any way they want, so it's probably handled by OS

#

you can try tracking screen.width or height

jagged fiber
deep jasper
#

no clue then

sage radish
# deep jasper well, it's done

Ok, so now you need to decide on what data you want to send to the shader. The bare minimum would be for each grass instance to get a Vector3 world position. Since you already have a buffer that contains all of the positions, it would be ideal to just read from that. So fullResBuffer and lodBuffer can contain indices that map to the positions buffer.
The Custom Function node which reads the _PerInstanceData would look something like this:

StructuredBuffer<float3> _GrassPositions;
StructuredBuffer<int> _GrassIndices;

void GetInstancingPos_float(in float3 PositionWS, out float3 Out)
{
    Out = 0;
    #if UNITY_ANY_INSTANCING_ENABLED
    int grassIndex = _GrassIndices[unity_InstanceID];
    Out = PositionWS + _GrassPositions[grassIndex];
    #endif
}
#

To be able to read the AppendBuffer like it's a StructuredBuffer, you'll need to add the Structured flag to it. It can be marked as both.

new GraphicsBuffer(GraphicsBuffer.Target.Structured | GraphicsBuffer.Target.Append, ...)
deep jasper
#

as i'm thinking

#

why do i need a custom shader

#

if anyways to draw a mesh using RenderMeshIndirect, i pass both mesh and material as params to the method

#

i can just tick gpu instancing in URP lit to true

sage radish
#

Because with RenderMeshIndirect, Unity has no information about where each instance needs to be rendered. Unlike RenderMeshInstanced, where you pass in an Matrix4x4 array.

deep jasper
#

thanks i get it now

#

so this code you sent goes into compute shader or the grass shader

#

default generated stuff

sage radish
deep jasper
#

so grass shader's hlsl part

sage radish
#

Yes

#

Instanced Grass Rendering

misty glade
#

I have a .. weird bug that I can't seem to figure out. I'm getting a MissingReferenceException but only after I'm using a debug tool to reload a scene. When I click through the error and examine the hierarchy, everything seems to be in order, and there's no weird DDOL or anything on any related component/GOs.

It's failing on a TryGetComponent() call within the object, but.. the stack trace doesn't make any sense to me.. Any ideas on what to pull apart?

Just so we're clear - I've debugged many many NREs and MREs and usually it's obvious what the problem is, but this one's strange.. The line of code that it fails on doesn't even seem related..

#

(I know this isn't a lot of info to go on but I'm not exactly sure where to even look for this one)

#

I can recreate and record a video in the editor if that's helpful, maybe

#

SimpleCancelDialog is just a full screen "click catcher" with a callback - but you can set the default color of it in case you wanted to change it at runtime or in a tween

sage radish
misty glade
#
        private void InitColor()
        {
            if (_image != null) return;
            if (!TryGetComponent(out _image)) // problem
            {
                w("SimpleCancelDialog contains no image and will not work.");
            }
        }
#

Here?

#

(that's the "bottomest" line in the stack trace)

sage radish
#

Yes, on the TryGetComponent

#

That's an implicit call to this.TryGetComponent, so this must be considered destroyed.

misty glade
#

I'm gonna start from ShowVictory() and dive in.. but all these items in the inspector are defined, and I don't think there's anything in the scripts unsetting inspector references

sage radish
#

This can happen with events, if you forget to unsubscribe from an event before the object is destroyed.

misty glade
#

hm.. it might be event related

#

I'm not unsubbing from the action in OnDestroy

#

(from the parent)

sly grove
sly grove
misty glade
#

lemme paste some code, maybe this is the problem:

sly grove
#
UnityEngine.Events.UnityEvent.Invoke () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
Coffee.UIExtensions.UIParticleAttractor.Attract () (at ./Library/PackageCache/com.coffee.ui-particle@6d8dee0b06/Runtime/UIParticleAttractor.cs:144)```
#

looks like an event subscriber

#

that probably wasn't unsubbed

misty glade
#
    public class GameOverRenderer : BetterMonoBehaviour
    {
        [SerializeField] private SimpleCancelDialog SimpleCancelDialog;
        public void ShowDefeat(GameDefeatEventArgs _)
        {
            SimpleCancelDialog.Initialize(() => OnCancelClicked());
        }
    }
    public class SimpleCancelDialog : BetterMonoBehaviour, IPointerClickHandler
    {
        public void Initialize(Action callback)
        {
            _callback = callback;
        }
}
#

wiill that break if GameOverRenderer doesn't unsub?

#

like - will it prevent the GO from being destroyed..?

sly grove
#

If whatever invokes _callback lives longer than GameOverRenderer you'll get a MRE when you try to invoke it

sly grove
misty glade
#

i'll dig, thanks.. that's at least a clue in the right direction

sly grove
# misty glade i'll dig, thanks.. that's at least a clue in the right direction
RuleOfCoolStudios.TwentyFortyEight.GameScreen.OnAllGoalAnimationsComplete () (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Screens/GameScreen.cs:251)
RuleOfCoolStudios.TwentyFortyEight.GameRenderer.GoalUpdatedCallback (System.Int32 goalIndex, System.Int32 beforeAmount, System.Int32 afterAmount, System.Int32 remainingAmount) (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Game/GameRenderer.cs:652)
RuleOfCoolStudios.TwentyFortyEight.GameRenderer+<>c__DisplayClass96_0.<OnGoalContributed>b__0 () (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Game/GameRenderer.cs:614)
RuleOfCoolStudios.TwentyFortyEight.ParticleSystemWithAttractor.OnAttractedCallback () (at Assets/Scripts/RuleOfCoolStudios/2048CE/VFX/ParticleSystemWithAttractor.cs:38)
UnityEngine.Events.InvokableCall.Invoke () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <f7237cf7abef49bfbb552d7eb076e422>:0)
Coffee.UIExtensions.UIParticleAttractor.Attract () (at ./Library/PackageCache/com.coffee.ui-particle@6d8dee0b06/Runtime/UIParticleAttractor.cs:144)```

Looks like there's 3-4 event-handler style things in this stack trace. I would check each of these event subscriptions and make sure they're all being cleaned up symmetrically.
misty glade
#

yeah.. i originally wrote an extension for it but it wasn't helping.. my "usual" pattern isn't great either since it's hard to see missing unsubs:

sage radish
#

This is all because C# doesn't care that an object gets destroyed. Everything in C# stays alive until nothing references it anymore and it gets garbage collected. So it will happily invoke an instance method on a destroyed MonoBehaviour if you tell it to.

misty glade
sly grove
#
RuleOfCoolStudios.TwentyFortyEight.GameScreen+<>c__DisplayClass43_0.<OnGameVictory>b__1 () (at Assets/Scripts/RuleOfCoolStudios/2048CE/Renderers/Screens/GameScreen.cs:246)

What about this one?

#

Looks like it's a lambda maybe?

misty glade
#

ie - sub in OnEnable unsub in OnDisable has worked for me

sly grove
#

Yeah that's good

misty glade
#

checking that .. but it seems correct

#

fuck.

#

spot the bug

#

genius crew as usual, thanks guys. 🙂

half swan
#

Oh dang. Just that one operator

misty glade
#

yep - double subbed instead of unsubbing

sly grove
#

ahhh yeah that's brutal haha

#

took me a second to see it

misty glade
#

this exact syntax bug has gotten me a handful of times over the years and I ... don't have a better pattern for this approach

#

Any ideas?

sly grove
#

also it makes me sad that those aren't in the same order haha

misty glade
#

i will fix that - usually i put them in the same order for exactly this reason

sage radish
misty glade
#

you know, a few months ago i tried to write one but it was too complex for my caveman brain

sage radish
#

I've seen libraries use a Dispose pattern for event subscriptions and a way to combine multiple subscriptions into one disposable.

misty glade
#

i probably should do some sort of extension in my BetterMonoBehaviour that has something like a signature of

public void AddSubscriber(delegate T delegateEvent, Action eventHandler);

that does somethign like add delegates and handlers to a list and then subscribes to everything in the list in OnEnable and unsubs in OnDisable but .. I don't know if I could get the generic part of it working

#

like, I'd love to be able to do something like:

public class SomeRenderingComponent : BetterMonoBehaviour
{
  private void Awake()
  {
    AddSubscription(GameManager.GameDefeat, OnGameDefeat);
  }
}
#

(and then the end result would be the same, without the high chance of fucking it up)

#

in any case, awesome job @sly grove as usual, add a beer credit to the tab

#

(and you @sage radish ❤️ )

scenic forge
#

I'm glad I don't have to deal with these issues because my game runs entirely on reactivity system, so things automatically unsub without me needing to write a single line of code that could mess it up or forget.

misty glade
#

UniRx?

scenic forge
#

No, it's my own much lighter reactivity system.

misty glade
#

I suppose I ought to explore something like this in the future.. but in general I like how I can loosely couple singleton domain logic classes with all of the UI

halcyon marten
#

when you have a large list/array in the unity inspector it auto adds a scroll bar anyway to get rid of that functionality, or control at what size it happens? do i have to make a custom editor function to display things a certain way instead

misty glade
#

it works for Action but would need to be genericized for different signature events

scenic forge
#

Yeah this feature requires a lot of buy in from the project, you pretty much have to build your entire project around using Signal.

misty glade
#
    public class GoalUpdatedEventArgs : EventArgs
    {
        public int GoalIndex { get; set; }
        ... etc ...
    }
    public partial class GameManager : ReloadableManager
    {
        public static event EventHandler<GoalUpdatedEventArgs> GoalUpdated;
    }

... elsewhere in a rendering component.. ...
        private void OnGoalContributed(object sender, GoalUpdatedEventArgs args) {}
#

that way all the events can have a huge number of named parameters instead of needing to do nonsense like Action<int, int, string, int, SomeEnum> and remember to get the things in the right order

misty glade
scenic forge
#

It doesn't matter what signature you use, as long as you have one single place where you subscribe to all events, which you can hook into, then you can build the auto unsub clean up.

halcyon marten
obsidian stump
#

Did anyone ever made a paper.io game replica.

plucky dagger
#

I have a prefab that consists of Slider and Buttons. A UIManager instantiates bunch of gameObjects at runtime. I need a way for buttons to get the information of Slider Value. Usually, I'd use something like, transform.find() but that only searches for child gameObjects which is not the case here. I can't do GameObject.Find() because similar objects (and name) for each of the dynamically created objects.

I think using events is a way to go but All the tutorials that I have seen don't really address how to use events during run time. It's easy to use unity events and drag and drop references in the inspector. But it's not possible when you are instantiating objects at runtime.

midnight violet