#archived-code-advanced

1 messages · Page 7 of 1

undone coral
#

this is in an editor script right?

#

i'm a little confused because the texture format doesn't have alpha right?

#

so why wouldn't it be full white

#

did you mean TextureFormat.ARGB32 or whatever?

#

i'm also not sure if unity reads pixel data into RGBA32 regardless of texture format, or if it gives you the texture bytes as is

#

you're at the start of a long journey

#

which specific reflection probe setting? you mean if you turn off reflection probe use in all your mesh renderers?

#

at least in HDRP, there's a native call early on during camera rendering (the culling step) that determines if a visible mesh is influenced by a reflection probe, and thus the reflection probe needs to be rendered

#

i assume it works the same way in URP because it has to work that way for all probes

#

this is regardless of whether or not it's realtime or not

#

if you have a realtime / on demand / on enable rendered probe, look carefully in the hierarchy to see if the flush is occurring during to the probe's rendering

#

essentially because the probe's camera sees geometry that is eligible for batching

#

srp batching is normal, i think unity writes about the approach extensively

#

there are certain settings that can put you in worse jeopardy than others

#

as background the reason i know all this stuff is because i was diagnosing an issue with reflection probes in a project of mine that sent me deep into the source code for this stuff

#

that concluded that there are bugs in the unity culling code you sometimes have to work around

livid kraken
#

All I have is a single baked ref probe

undone coral
#

so it's very possible you are encountering a real bug - it is probably not culling probes for you, so if you have X more than N in your scene, for example, where N is the "optimized" limit in URP for probes, it has to choose N of X probes to use during rendering (blending) for an object, and this choice might "jitter" between even nearby objects, which means that they will appear to need their own rendering command instead of many objects sharing the same rendering command (i'm not going to use the word batch or draw call here because that's even more confusing, with legacy baggage)

livid kraken
#

That causes SrpBatcher.Flush to take 8ms

undone coral
#

does srp batch flusing go away?

#

the features probe blending and box projection here may also cause distinct render commands

#

and do you have a blend distance set on the probe?

#

maximum two of the probes 
so N = 2, but you only have 1 probe

#

it's possible that there is some weirdness with 1 probe

#

srp batch flushing might be a red herring btw

livid kraken
#

Dont know about turning it on and of Im mot at my pc anymore sadly. I will try tomorow

undone coral
#

okay

#

like sometimes the accounting shows up in weird places

#

if it's taking 8ms more CPU time to use a baked probe than not, that's weird

#

however, that doesn't necessarily mean there's anything wrong with the probe

#

do you only use Lit & shader graphs you've made yourself?

#

srp batch flushing taking a while is just saying that suddenly it cannot optimize many objects sharing the same render "command" - but it could also mean that some scene configuration changes where you are NOW eligible for srp batching whereas you weren't before

#

that's what i mean by red herring

#

and it may be in your game, you use GPU instancing (which isn't compatible with srp batching)

livid kraken
#

I dont I know about that

undone coral
#

and just because you check the gpu instancing box doesn't mean it will use gpu instancing

#

okay

#

for example, there might be a shader that samples the reflection probe

#

and it may interact weirdly

livid kraken
#

Thats the shader I made

undone coral
#

did you build it in shader graph?

livid kraken
#

A what I call a unlit with environment reflections

undone coral
#

okay well now we're onto something 🙂

#

so i have bad news for you, first off

livid kraken
#

No I dissasembled the whole brdf structure and SampleGI method

undone coral
#

there's no such thing as unlit with environment reflections

#

at least if you want to use reflection* probes as they exist in the engine

#

you can always take that cube map and funnel it in instead

#

this is most likely to make your problem go away

undone coral
livid kraken
#

I could do try that too

undone coral
#

okay well try using the cube map directly

#

and don't have a Unity reflection probe at all

#

there should be a CG include with how to sample the reflected cube map correctly, or you can look at the shader graph source to do that

#

it's something idiosyncratic

#

@livid kraken otherwise i understand the appeal of authoring an uber shader but there are also lots of pre-existing ones, some free on github some on the asset store

#

that someone has already relentlessly optimized

#

and those typically have you slot in the reflection cube map directly

livid kraken
#

Thing is this shader was birthed from a joyrney of optimizing a scene for the Quest 2

undone coral
#

yeah

#

well they'll never admit how crappy the qualcomm chip is

livid kraken
#

It samples a globally set texture array for the atlas with the slise being baked into a exrtra component of the uv to minimize attribute data

undone coral
#

and i think the quest 3 is massively delayed

livid kraken
#

I dont really want to create multiple materials for the env so that they can sample different cubemaps

undone coral
livid kraken
#

I know Im sampling it correctly since I "yoinked" the sample from the lit urp shader

undone coral
#

and like the 4 box centers of where they're supposed to influence

#

they like... loop unroll that whole thing

#

i think as soon as you add the cubemap slot you'll be fine

livid kraken
#

Its far from a uber shader. If anything its a very narrow specific shader for the environment of a specific quest 2 experience

#

I should mention it runs fine in the actuall scene

#

Frame time is 4 ms

clever relic
#

Heyall is there any way I can make Unity allow me to create some objects on another thread other than it’s main? I’m building an editor utility that creates thousands of textures and other assets and it would be nice to have these tasks leveraging the full potential of my cpu

livid kraken
#

In my test scene with 4096 cubes is where the problem starts

undone coral
#

have you looked at the shader that comes with the Steam lab demo scenes in unity?

#

some of the interesting stuff they did, which is as old as 2016, is implement dynamic resolution

#

and stuff like that

livid kraken
#

I have already yoinked that too

#

We have dynamic res scaling in all our games heh

undone coral
#

okay great

#

well good luck on the journey of not uber uber shader hell 🙂

livid kraken
#

Fun fact the same dynamic resolution algo runs in Alyx as well

undone coral
misty glade
#

I recently installed a more aggressive linter and it's complaining about my use of public members in Unity. What's your convention/solution to the following?

public GameObject MyGameObject; // S1104 Make this field 'private' and encapsulate it in a 'public' property.

A: Disable this particular rule and live life to the fullest.
B: Use a manual property and give it an inspector name (or not):

public GameObject MyGameObject { get => _myGameObject; set => _myGameObject = value; }
[SerializeField, InspectorName("MyGameObject")] private GameObject _myGameObject;

C: Use the auto backing field with the field attribute:

[field: SerializeField]
public GameObject MyGameObject { get; set; }

D: ??

#

(My complaint about "B" which seems to be the convention is errors are cryptic because they put out generated field names like k__BackingField__001__GameObject)

sly grove
#

or just [SerializeField] private GameObject x; because most of the time you don't need any access from outside the class

misty glade
#

And if you don't? Like, for a display object that might have dozens of TextMeshProUGUI objects where you're 99.99% just setting .text or something insignificant? This would represent a pretty substantial addition of boilerplate

sly grove
#

then this:
[SerializeField] private TMP_Text nameLabel;

misty glade
#

Hm, that's probably the best approach. I think it jives best with limiting the public members anyway. Most of my objects on scripts "are" private (but I've just left them public to set them easily in the inspector). I could change them to private and serialized without any trouble. I can't remember why I didn't do that as convention in the first place..

#

on one hand, adopting a new analyzer/linting tool feels nice but on the other hand......

umbral parrot
misty glade
#

Heh.. I generally try to TWOE though so.. I mean, especially if I'm going to be bringing on another dev in the next few months, I want to at least be able to say "here's our standard analyzer, use it, don't check in things that fail it"

#

I shouldn't really pick and choose which rules I live by if I'm gonna pay someone else to live by them 🙂

umbral parrot
#

what does TWOE mean??

misty glade
#

this linter doesn't work super well with Unity though unfortunately, I suppose I'll have to configure some stuff

#

treat warnings as errors

#

linter thinks all unity messages are unused :p

umbral parrot
#

yeah that's annoying. i usually just stick with unity tools for vs, it works really good for me

gray pulsar
#

I wish you could do something like a C #define

#define inspectable [SerializeField] private
#

I don't think that's possible in C# though

misty glade
#

that's an interesting idea

#

i'd be leary of adding my own #define like that to a codebase though, but.. i like the idea lots

umbral parrot
misty glade
#

i mean, I think it's not really hiding it since he's making a new word inspectable

gray pulsar
misty glade
#

but yeah, I can't really put my thumb on why I think it would be a scary addition, but... it feels scary 🙂

#

While we're sorta on the topic - anyone know how to configure various rules of a given analyzer? Do I just have to supress them ione by one in a project suppression file?

umbral parrot
umbral parrot
#

I actually was looking at that earlier today to try and supress some errors I was getting on IntelliSense in a .hlsl file even though it was all fine: it just didn't knew the unity macros. VS support for hlsl is really bad imo

misty glade
#

Yeah I'm going to have to do this globally since my new analyzer is complaining about hundreds of Awake/Update/etc messages that are "unused". I always have to google up the syntax on these global suppression files

#
[assembly: SuppressMessage("Roslynator", "RCS1213:Remove unused member declaration.", Justification = "<Pending>", Scope = "module")]

I think this is correct and hits all the projects in the solution

#

(ie - scope = "module")

umbral parrot
#

I've never done it before so I can't help. Also never heard of Roslynator, so yeah good luck

misty glade
#

almost no impact on my server-side solution aside from a few hundred whitespace complaints (like an extra space at the end of a line)

#

lol at that comment btw

umbral parrot
#

I started coding on a very basic IDE (Codeblocks), so all this vs suff is still pretty new and overwhelming to me, that's why i usually just stick with intellisense.

#

Also i don't mind "bad" code, I usually just code by myself, so no one will criticise

misty glade
#

I'm a VS fanboi. The only things that make me mad about VS is blazor/razor tooling issues and bug reporting/handling by MS

#

You should be as aggressive as time permits towards bad code since.. even if you're only doing it yourself, you'll come back to it later.. plus, having really robust but not overly clever code means A) lower incidence of bugs and B) bugs you do have are easy to find and fix

urban sequoia
misty glade
#

(imho)

umbral parrot
umbral parrot
misty glade
#

hehe

#

well i also did qualify it with "time permitting"

#

I did a game jam recently where the code i produced was embarrassingly bad .. but.. you know, game jam things

quartz stratus
#

Does anyone here have a preference between

if (myObject != null)
{
  // do something
}

versus implicitly casting to a boolean

if (myObject)
{
  // do something
}

?

Assuming myObject derives from UnityEngine.Object. Of course, while there could be valid readability/design preferences here, I'm also trying to figure out in the Profiler if there is a performance difference between these two options. But I haven't been able to discern anything meaningful yet. Thanks in advance if you weigh in!

misty glade
#

The performance difference in the above is insignificant.

If your object is implicitly a boolean (like, if it could be named isJumping or hasObject or doesAction) then it's fine from a readability perspective to if(isJumping), but it sounds like you're using game objects, so I would never use an object like that since you're likely to step in poo

#

(because UnityEngine.Object has overloaded operator== and it doesn't mean what you think it means, typically)

livid kraken
misty glade
# quartz stratus Does anyone here have a preference between ```cs if (myObject != null) { // d...

Also, in general, build first then profile. The real hits to performance in your game are not going to be in trivia like this.. they're going to be situations where you FindObjectOfType in your update methods, or Instantiate() when you don't need to, or have deeply nested prefabs, etc. All that low level math stuff is like.. many, many orders of magnitude less significant.. like nanoseconds of difference, even for several thousand/million iterations

quartz stratus
#

Thank you both, super helpful

vivid talon
#

How does Canvas.targetDisplay behaves on a WorldSpace canvas that moves across displays?

humble onyx
buoyant leaf
#

I'm having problems with the sprite revolver

#

I can't "animate" the label hash

#

when I try to animate it, it animates the sprite key instead?

#

I just switched from 2020 to 2021

heady bane
#

what can I do to confirm touch input simulation is working?

analog verge
#

Is there any way to execute my code before unity engine initializes opengl/d3d device?

analog verge
#

To initialize Steam API

undone coral
#

i think you can just do that as normal

#

you can use script execution order or runtimeinitializeonload to do that early in your game

analog verge
#

Of course I can but if I do it after that, Steam overlay doesn't appear

#

And script execution order may doesn't work because the graphics API is initialized before executing MonoBehaviour

austere jewel
#

I don't think any steam API relies on you calling initialise at some insanely early point

undone coral
#

the steam overlay appears for me

#

what exactly do you mean?

#

you don't even need steamworks installed for the overlay

austere jewel
#

If you're using Facepunch.Steamworks you have to make sure you're also calling Steamworks.SteamClient.RunCallbacks(); in Update

undone coral
#

the graphics device initialization has nothing to do with the overlay

#

steam already has special handling for unity games, it is aware of them

analog verge
analog verge
analog verge
deep peak
#

obviously

undone coral
analog verge
analog verge
austere jewel
#

You can replace the files in your steam directory, it'll just require you re-validating the files when you want to sync back to steam

undone coral
#

you might want to just copy and paste your game into the steamapps directory

austere jewel
#

You may want to force-reopen it through steam for players in the final build

if (SteamClient.RestartAppIfNecessary(AppID))
{
    Application.Quit();
    return;
}```
undone coral
#

jinx

deep peak
#

if you add your exe as non-steam app, and run through steam you have overlay

undone coral
analog verge
#

Maybe I should make a new Steam build branch for testing

undone coral
#

yeah i use a testing branch

analog verge
#

One of the reasons I don't want to upload to Steam build to test is there can be corrupted builds uploaded during development

#

Anyway, thanks for your help @undone coral @austere jewel @deep peak

north tundra
#

how do i format my code to send in here

#

sorry i just joined

sly grove
north tundra
#

ok

sly grove
north tundra
#

ok

#

sorry

hexed meteor
#

What could be causing AddComponent to simply not work?

#

The code works fine except for the last line, it's simply being ignored

compact ingot
hexed meteor
#

it instantiates the new gameobject ...

compact ingot
#

why?

#

do you need two of them?

hexed meteor
#

no, just one. the first line declares the gameobject and creates a variable referencing it

#

the second line instantiates it in the scene

#

it's the same gameobject though

compact ingot
#

You are creating two game objects there

untold moth
#

Calling a GO constructor already adds it to the scene.

hexed meteor
#

oh no

#

So how do I create an empty gameobject X in one line of code?

fresh salmon
#

You're doing it

compact ingot
#

Your first line does that

fresh salmon
#

new GameObject()

hexed meteor
#

oh okay!

#

Thanks guys, it works now!

stuck onyx
#

Anybody familiar with this type of stacktrace?

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  Module "System.Runtime.ExceptionServices.ExceptionDispatchInfo", in Throw
  Module "System.Threading.SendOrPostCallback", in Invoke
  Module "UnityEngine.UnitySynchronizationContext+WorkRequest", in Invoke
  Module "UnityEngine.UnitySynchronizationContext", in Exec````
#

It doesnt help me at all to know which script or method is being thrown from

#

so far i understand an index was out of range , and the variable out of range was called index... but nowere i see where is the origin like i see in most stacktraces... why is this?

fresh salmon
#

Never seen that, it's not C# at least

#

Maybe JS? JS has Modules

flint sage
#

It looks a bit like there's no symbol information at all

fresh salmon
#

More info required! Where are you seeing that stack trace?

stuck onyx
stuck onyx
#

maybe it's their fault

fresh salmon
#

No idea what that is ¯\_(ツ)_/¯

wispy terrace
#

I usually get thos when, well, the index is bigger than the length of the array

stuck onyx
#

the thing is im not 100% sure which method comes from due to the lack of information of the stacktrace but if it is the one I think this comes from inside of a Unitask, could that be the reason?

#

and yeah that method goes across lists using for, and one of them i use 'index' instead of i which i use normally

#

okay but now i got another exception is not inside a unitask and has the same structure

#

this must be the sdk's fault

#
System.ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime.
Parameter name: value
  Module "System.Runtime.ExceptionServices.ExceptionDispatchInfo", in Throw
  Module "System.Threading.SendOrPostCallback", in Invoke
  Module "UnityEngine.UnitySynchronizationContext+WorkRequest", in Invoke
  Module "UnityEngine.UnitySynchronizationContext", in Exec```
wispy terrace
#

If you are usin extensions, then i cant help you xD

stuck onyx
#

yeah sorry, i didnt think it was the exception reporter

#

well... im still not sure but seems like

undone coral
stuck onyx
#

yeah it would not be the first time

#

i just wanted to know if any of you felt that stacktrace familiar

undone coral
#

you can try breaking on the exception and checking if it has an InnerException set

#

and it will show you what the real issue is

stuck onyx
#

can't reproduce , im getting it once every 100 games or more

#

i wish i could

undone coral
#

i don't think sentry can help you much in unity though, it can't instrument the code can it?

stuck onyx
#

it's very helpful

#

more than Unity diagnostics

undone coral
#

for example they claim "Line numbers for C# exceptions in IL2CPP builds." which is dubious

stuck onyx
#

they are working on that

#

and not just for Unity 2022

#

also 2021 and 2020

stuck onyx
undone coral
#

yeah

#

that's what i'm saying

stuck onyx
#

yeah thats a big shit

#

but they claim they will make it available for 2020, and 2021 while unity said just for 2022

undone coral
#

the team of like 1 person who does't know how to make anything in unity at sentry isn't going to know how to do anything

#

i guess what i'm saying is that it's not reliable

#

i understand they SAY they will be an APM but it probably doesn't work a lot of the time

#

not just line numbers but in general

stuck onyx
#

well youre right, sometimes stuff fails but they have a team of 2/3 people working on the Unity SDK constantly

#

It's quite useful compared to Crashlytics or Diagnostics, just saying

undone coral
#

same with the tracing... it's a very odd thing to promise

stuck onyx
#

the stacktraces i've been getting are totally fine most of the time

#

but yeah sometimes shit like this filters

#

but as I said... they work on it constantly and i have someone to complain for 😅

#

also the dashboard is amazing

undone coral
#

they're just making promises there is no way they can keep

mortal egret
#

does anybody know how it works? I need to get camera depth texture but there's always nothing

undone coral
#

i know what box you have to check, but you're still probably doing something wrong

mortal egret
regal olive
#

why there are weird values appear on intensity of chromatic aberration?

fresh salmon
#

You should share the code that changes this intensity setting

regal olive
fresh salmon
#

So the two Lerp might conflict hence the back and forth movement of the intensity.
Check that both can't run at the same time

#

Maybe by using else if? Hard to say, depends on what affects the chromatic aberration

regal olive
heavy ether
#

Hello, does anyone know how to make an automatic login with facebook? I manage to make the user log in but I don't know how to save the AccessToken

heavy ether
undone coral
#

what is your game? (in one sentence)

undone coral
#

or what login is

#

are you trying to say

#

"i want users to be able to 'login with facebook' in a colloquial sense, and thereafter whenever they reopen the game, they are not prompted to login anymore" ?

heavy ether
undone coral
#

you should probably use PlayFab, GameSparks or something similar for user accounts

#

you can use firebase for unity if you need a comprehensive solution for backends

heavy ether
#

And there is no other way to make the user not have to login again?

heavy ether
#

The game is not multiplayer, the only thing you can see is the ranking of the other players and the profiles of the game

undone coral
#

what did you put in there?

#

i understand what you are trying to do and that you are looking for a simple solution

#

if any meaningful number of people start playing facebook will boot you if you don't do things right

#

i assume you are still running in test mode

#

the token facebook gives you, you can later query through an API to see what ID is associated with it. they aren't signed, but as long as you use the API, it will only return the real ID associated with it. the token is just an identifier, it doesn't encode data

#

does that make sense?

heavy ether
heavy ether
undone coral
#

show them the login option if the token is invalid

#

you can store that token

heavy ether
#

The token when closing the application is deleted, I try to save the token in a scriptable object but it is also deleted

undone coral
#

well there's your problem

#

you can try saving the token into PlayerPrefs

#

this was a #💻┃code-beginner issue, and in quintessential XYProblem form, your X problem was actually "how do i save things between app loads"

heavy ether
chrome dune
#

Hello! I am trying to do a map builder (imagine trackmania map builder), and I was wondering if some of you had some kind of link to tutorials or techniques to save the data, like position/rotation/extra data efficiently. Thanks!

fleet mist
#

Well you can use json files...

#

I would suggest using Newton Soft if you choose this path. It's typically better than unity's JsonUtility

somber grotto
#

how does this code work? never seen it before

#

oh is it just if (weightedInput > 0) return 1, else 0

sage saffron
#

Ow that's some dense code lol

brazen lynx
#

That's called a ternary operator

#

If the boolean is true, it uses the first value

sage saffron
#

Looks pretty useful

brazen lynx
#

Otherwise it uses the second value

somber grotto
#

that's very cool

chrome dune
somber grotto
#

how do i add weight to my randomization in unity?

i'm randomly spawning fruits out 10 options, but i want to be able to modify it so fruits later on in the list spawn more

quartz stratus
#

Easy

#

And of course would be more performant to not create the second with the original objects, but with some type of lightweight key that points to the original object.

#

Perhaps you could store the original fruits in a dictionary

#

And then use their keys to populate the weighted list

somber grotto
#

oh i might have come up with something else, maybe make a curve and then use the initial random number to get the point on that animation curve, then you can change the curve to have any weight you want??

#

i need to specifically be able to control it semi easily, and i feel like that might work

rugged radish
#

I realized that I made a better version, because the sorted requirement was annoying me

public int WeighedRandom(List<float> weights)
{
    // modifies the collection
    float total = weights.Sum();
    if (total == 0) return -1;
    else
    {
        float weight = 0;
        for (int i = 0; i < weights.Count; i++)
        {
            float probability = weights[i];
            if (weight == 0 && probability != 0) weight = float.Epsilon;
            weight += probability;
            weights[i] = weight;
        }
        float rngWeight = rng.NextFloat(float.Epsilon, total + float.Epsilon);  // dodging zeros in the beginning
        return weights.FindIndex(p => p >= rngWeight);
    }
}```
regal olive
wheat mango
#

how do you actually connect a random seed with procedurally generating objects?

#

in this tutorial they don't seem to connect the two:

queen stirrup
#

Sorry if this isn't advanced enough for this channel...Is there any way to hijack/override a method from another method for the sake of keeping code clean? Usecase: Text game. I'm adding "aspects" which change the way things in the game works. If I had, say a "darkness" aspect, that I wanted to hijack the room description generation method to change it to "it's dark in here" from within the aspect's code instead of the room's code. The reason is so that when I add the other [x] number of methods, the code within Rooms, items, and NPCs isn't absolutely bloated with "aspect" if statements and instead those are just hijacked from within the aspect code

compact ingot
#

if you prefer a "raw" way you can have aspects publish some events or delegates that you can inject handlers into (from the outside) which then modify the behaviour of the aspect

queen stirrup
#

Thanks, I don't know a ton about event busses but I will look into it because it seems like the best way to go about this.

#

Because this seems like what I'd want it to do. Let me see if I have it right. Say I make another aspect, "Poison". Using event busses I'd be able to make it so if a food is poisoned, it'd poison you. If a weapon is poisioned, it'd poision who you hit. All within the aspect itself. Wtihin the food command it'd be like: "Eat { do eating actions, also alert all aspects that we're eating":, and "Weapons {do fighting actions, also alert all aspects that we're fighting}" then within the poison aspect I could be like "ope, the eating alert just got passed, let me check quick to see if it has the poison aspect attached to it. If so, we'll modify it to take away health at the end."

buoyant leaf
#

is there a way to revert to the old way of working with a sprite resolver

#

now when I try to animate anything with a sprite library, it chooses the sprite from the category that I animated with, rather than setting it to the equivelant sprite hash within the preset category

#

which isn't really helpful to me since I started using it like that in 2020 because I can have the same animation with sprite swapping depending on the circumstances

undone coral
#

you can look at the xmage or spellsource source for an example of how to architect these kind of games

undone coral
#

you can't just ad lib it

#

if you wanna avoid a spaghetti code mess like hearthstone

#

the super abbreviated version of this architecture is that your game rules executing looks as much like a conventional c# program as possible... with the magic that the code is also data and can modify itself

#

C# isn't a LISP, so that's hard

#

in spellsource, my card game, which has a poorly implemented version of half of common LISP

#

an effect like All draw card effects discard instead looks like

{"type": "ModifySpellSpell",
 "target": "ALL_CARDS",
 "spell1": {"type": "DrawCardSpell"},
 "spell2": {"type": "DiscardCardSpell"}
}
#

the reason this works pretty simply is - every spell / effect, if it were a conventional C# function, would have the same exact function signature

#

it's up to the function to decide how to interpret the function arguments, including possibly using none of them

sly grove
#

Whoever at Wizards of the Coast did the code architecture for Magic Arena (and MTGO) has my pity and respect.

sly grove
#

I'm pretty sure the card engine needs to be a turing complete system

undone coral
#

@queen stirrup so there are many discoveries along the way that you have to make. think of this like a tech tree:

in the Architecture tree:

  1. Execution
    Your game stack looks like your C# stack

  2. Pre-emptibility
    Your game execution can be stopped, serialized, deserialized and resumed at any time

...
19. Algorithmic Content
You express your game content, like card text, algorithmically
20. Homoiconic Implementation
Your content format is both code and data
...
40. Function Rewriting
You can instruct your game virtual machine to replace a function anywhere or everywhere

undone coral
#

and render from its state

#

with a clear, demarcated API between the card game and wherever it is hosted

sly grove
#

definitely some language like that - or ruby which can rewrite itself at runtime is needed

undone coral
#

i'm sure the hearthstone people wish they did things this way, although Snap just the same hearthstone approach of a C++ backend

#

roblox has fairly primitive replication, but it is greatly assisted by shipping diffs of lua runtime state as a black box

sly grove
#

i have no idea how hearthstone works but the mechanics of hearthstone are much simpler than MTG

undone coral
#

it stands on the shoulders of giants

#

i met the contractors who do MtG Arena, who were selected because they had experience porting a lot of very text-driven board games

#

like they did many avalon games' mobile ports

#

anyway when people say they want to do code rewriting

#

i don't know, i just imagine the alpha centauri tech tree

#

they want to rush to air power, which is only 5 techs away, but default rules are you get techs from a lane randomly so you can't just

#

go for it

#

the default rules are more realistic. you fumble around learning 15 techs you don't need for air power

sly grove
#

Sorry Doc you've gone off on a tangent now 😛

undone coral
#

lol

#

@sly grove https://i.imgur.com/IbzHn6A.jpg okay, as you can see, Doctrine Air Power only has 4 prerequisites techs so can be reached very quickly, however in this game you can't...

#

(40 minutes later)

grim oxide
#

I have a project, I want to break some of the systems into separate code libraries so I can use them in other games and more easily update and so on. How does that work in Unity? 🤔

misty glade
gray pulsar
hallow cove
#

so I have these SearchTreeEntries cached in a ScriptableObject

#

and if I create the ScriptableObject, it works fine

#

but the moment I recompile, even though all the data is there

#

it doesn't work anymore

#

and throws an exception

#

missing reference for some reason

novel plinth
#

Scriptable asset cant refer to scene objects proly that was your issue

hasty hinge
#

can i create ipa file for ios?

#

from unity

upbeat path
hasty hinge
#

im bulding using windows but compiling using mac

#

will i ran to issues?

upbeat path
#

no, that should be fine

hasty hinge
ruby gull
#

Hi there, I'm looking at some decompiled code at the moment and I've noticed that in this condition, the compiler has automatically recasted all the floats into doubles.

My understanding is that casting is expensive, is there a reason the compiler would do this?

#

Sorry for this being a more C#-oriented question

flint sage
#

Check the IL to see if it's actually casting

#

It might just be the decompiler making assumptins because it doesn't know for sure

ruby gull
strong harbor
#

I had a question that I am unsure if anyone can answer but I have gotten to a point where I think the best I can do is just get more eyes on it.

I am currently working on a dungeon generator that involves a far more tiny keep algorithm idea. Basically i spawn a bunch of rooms, then I am trying to A* to make all the hallways. Right now the formation of the hallways works, but what specifically has just not made sense. Right now my cost function for the A* algorithm has a lot of extra workings in it. But one thing that has stayed constant is it increases the cost more to go through a space in my grid if its nothing then vs if its a hallway. So despite everything, I am really confused why stuff like this happens (red squares are just my debug fill in for what the world sees as hallways) (green squares are fill in debug space for what the game sees as being the room)

Would anyone have any idea why this is forming when I am encouraging the A* to go through existing hallways?

#

I can also show any code anyone wishes to see

wary swift
#

I'd help you but unfortunately I've got no clue what your question is nor what I'm supposed to see in that picture

strong harbor
#

My apologies I can elaborate

#

Basically, the way my system works right now for what matters, is that i form a graph of all my rooms to determine what hallways to create such that you can traverse all the rooms for the floor in the dungeon

#

that system for making the path of the hallway is an A* algorithm

#

the hallways in this case are made up of red tiles mainly to show for myself in debug what the code knows are hallways.

#

My confusion has become that part of the A* cost function (determining the cost of moving to a certain tile) makes it in a way where it should cost less for any hallway to move through a hallway that already exists

#

Yeah i dont understand why when the cost function should make it such that a hallway would always prefer moving through an existing one, you get something like the above picture where it just goes next to it instead

wary swift
strong harbor
#

that is why actually if i blow that picture up

#

you see a lot of cross roads like this

#

because its supposed to try to reuse as much as possible

wary swift
#

Okay can you elaborate what your cost function does?

strong harbor
#

sure

wary swift
#

Because if I'd implement this I'd simply use Manhattan distance as heuristic and then increase the node weight of all cells which are empty (but I believe you said you did this)

strong harbor
#

the cost function takes in two nodes. Node a, and Node b. Node a represents the current node on the path. Node b represents the node that we are checking to see what its cost would be if we added it to the path. Because the goal of an A* algorithm is to get from the start to the finish with the cheapest cost

It first begins by setting the base cost of b to its distance to the end, then it will increase the cost of b by a myriad of factors I have set up

the distance cost beginning is heuristic

they line up particularly in this order:

if we are trying to attempt to perform what i call zig zags (basically go diagonal) increase the cost (this encourages straight lines which are easier and make more sense, also makes turning far less common)

if we are too close to a room increase the cost (this is to give ample space between rooms and hallways

we then increase the cost of the node based on what type of node it is with the highest cost being a room, second highest being empty, cheapest being hallway.

that is all

wraith snow
#

Hey all, I'm having an issue with the unity standard assets. I downloaded the entire third person asset and I loaded the demo scene. I cannot get the mobile controls to work
I'm building targeting android and I have the game showing in unity remote
but its not reading or reacting to any touch inputs

wary swift
#

I might be wrong on this but you might be cluttering your cost function a bit (people might disagree with me here)
If you want to discourage A* from going near room, can't you simply increase the weight of nodes near the rooms?

strong harbor
#

that is basically what i am doing

#

its just wacky because technically the nodes are per path

#

so for each hallway the costs are all redone

#

because they have a different starting and ending context

#

what may cost 5 in one hallway may cost 20 in another

wary swift
#

That sounds normal

#

Gcost is the travel cost to reach this tile from the starting point
So it's normal that it is not the value when you start from a different starting point

strong harbor
#

right but regardless of that reset

#

it should still prefer going through hallways

#

the only thing i can think of is maybe it doesn't know its a hallway for some reason

#

but that wouldn't make sense given the entire other context of 90% of the time it works

wary swift
#

I think your best course of action is to reproduce this issue in a small scene and go over the code with an debugger

strong harbor
#

i agree

tidal maple
#

do someone know how can i make my game moddable by loading a mod .dll at runtime?
and how can i make a custom API for modders to use

severe trail
#

Hey, anyone out there have any experience with the material array in a Skinned Mesh Renderer?

#

trying to figure out why it changes the sort order of my materials

#

keeps swapping the slots

#

is it based on vertice order?

#

how does it decide what order to list the materials in the array?

sly grove
severe trail
#

I should clarify

#

so when I import a model, the skinned mesh renderer reorders the materials

#

so 01_mat is in the second slot, 02 in the first of the material array

#

no scripts

#

trying to find any info on how that sort order in the material array is decided

#

and if there's a way to override it, as I need my 01_mat to be in the 01 slot

undone coral
#

in Unity Metal, does a CPU and GPU texture point to the same memory?

#

e.g. if i request the gpu texture and the cpu texture for a RenderTexture, i might get different pointers but are they backed by the same buffeR?

#

because it is unified?

barren stump
#

Guys, I have been trying to do something but I just can't seem to figure it out

#

Say I have an object that collides with the object in the image above at the red dot

#

So the collision is at the red dot.

#

How do I find the angle of the green arrow? It should be perpendicular from that object in the image

austere jewel
#

It's the normal of the collision

#

which is generally provided in the collision object

barren stump
#

Though doesn't the normal give the direction between the collision point (red dot) and the pivot of the object that collided?

austere jewel
#

No

barren stump
#

Oh. Thank you

#

Or is my code wrong

#

I also tried pushBackDirection = collision.contacts[0].point.normalized

flint sage
#

Not what you're doing

barren stump
#

How do I use it, ContactPoint2D pops up, but I can't write ".normalize" or ".normal" after it... I'm sorry I probably shouldn't be in #archived-code-advanced

#

Ah... I got it...

#

nevermind....

viral flicker
#

How do i implement a complex combo system similar to platinum games or DMC games in 2d ?

#

i can only think of a tree structure, where player click one attack button and then he has a possible combo he can move forward to

snow flint
#

hi guys, found some really good threads and info about having using json in this channel
i was wondering if anyone... has a good tutorial or example i can learn from to do this...
similar to a card game where you have a card that has spells... i want to do something the same/similar
read data from json, use it to populate actions/spells in game

barren stump
#

Hey, I just figured it out. Thank you vertx and Navi, I'm not going to ping you guys but thank you

snow flint
urban sequoia
stuck onyx
#

im having trouble with the EventTrigger, i have a list of buttons dinamically created and in order to know which button the user has clicked i use

#
myButton.onClick.AddListener(() => OnClick(buttonID));
#

but with the EventTrigger i can't pass parameters

#

(I want to use onPointerDown and OnPointerUp, in order to hold and push multiple times)

#

I dont see how can i do this if i can't pass he 'itemID'

silk sable
#

This seems valid

stuck onyx
novel plinth
stuck onyx
#

so the user can tap and hold

#

but the problem is the EventTrigger doesnt allow me to send the button's id

novel plinth
#

proly you should elaborate a little bit, bcos I see no reason why your sinppet won't work

stuck onyx
#

my snipet works, but its an onclick event

#

so it triggers when you make a click which is tapdown and lift finger

#

but, i need to tapdown... detect how long has been holding down... and decrease

stuck onyx
#

Exactly

#

now the problem with this is, how can I pass a parameter to tell which button has been pressed?

#

can i use the PointerEventData?

#

to send it there somehow '

#

?

stuck onyx
#

i can use the PointerEventData? oh i didnt know thatr

stuck onyx
#

ah great great, i didnt know i could set custom info there, i thought this just holded info about the click event

#

thanks a lot

novel plinth
#

goodluck

novel plinth
#

So you can pull out the id of your gameObject of which the event belongs to, and check on your side if that id belongs to which button etc

stuck onyx
#

that sucks a bit but well... better than nothing

novel plinth
#

It doesn't, it's just a pointer to your object which the event belongs to... Whether you want to get the InstanceId or not it's up to you
I mean, you said they're dynamically generated which I assume they're instantiated... so InstanceID makes a lot of sense here

#

Unless you have your own id system, then use just that yeah

zinc osprey
#

Hey idk if this question belongs here, but i'm somewhat new at programming and currently working on a game with unity. I was working on it just fine yesterday, mainly messed around with the level design, but when I opened it up today some of my scripts were encoded like this and I have no idea what caused it or how to fix it. Could someone help me out?

stuck onyx
novel plinth
#

you can get the reference to the object for sure, like anything else with UnityObject 😆

#

just read the doc that was linked

novel plinth
stuck onyx
#

AHHH

#

okay perfect

#

👍 thanks a lot

novel plinth
#

goodluck

#

now that I think about it, you're too overthinking your simple issue 😆 but that's totally fine

novel plinth
#

make a list somewhere to pool your buttons, static or not it's your choice. Add a listener that will execute a method with the id of the button for as it's param

#

the go from there, like you can do filtering and whatnot it's up to you

#

so when you're checking things, just check what's in the list

livid kraken
#

so.... Friday everything builds fine. Today I get to the pc, install a mandatory windows update and suddenly I can no longer build for android, getting this error : https://hastepaste.com/view/ZMRTj

#

What have I tried so far, Installing the android module again, complete fresh install of unity with the module, deleting gradle cache, making sure I have the correct keystore( its a debug key), updating java, deleting project library folder, doing a clean build

novel plinth
#

there are nasty bugs in 2021.3.3 - 5 for android builds, I believe they fixed this in 2021.3.6, what version you're using?

livid kraken
#

2020.3.37f1 LTS

plucky laurel
#

if there is a panic over that update youll just have to wait

livid kraken
#

well well well, the mystery deepens a fresh project on the same version does build

plucky laurel
#

maybe library nuke?

livid kraken
#

I did that, right now I'm doing it a second time

#

just to be sure

plucky laurel
#

nuke csproj/sln

#

.vs folder for good measure

livid kraken
#

So il2cpp build fails....

#

But how

#

Like build the gradle project manually ?

upbeat path
livid kraken
#

Yes

upbeat path
#

do you have Android Studio installed?

livid kraken
#

No

upbeat path
#

Try installing that and then use the SDK from there

livid kraken
#

But it was building fine last Friday I shoudnt need Android studio because windows updated

upbeat path
#

True, this error seems to come from a duplicate library somewhere, did your Java SDK update with the windows update?
Clutching at straws here but you are not the only one with this exact error

livid kraken
#

I had a pending jvm update that I did but after the build started failing

#

I can try and remove java, and all android modules from other unity versions on the machine

#

See if that magically fixes it

upbeat path
#

thats why I was thinking Android Studio, to take the whole process out of Unity

livid kraken
#

Ive done that in the past. Build a android studio project from unity and build out apk from the studio itself

#

Idk Im really frustrated atm and have a doctors apointment so I cant keep poking this problem

plucky laurel
#

@livid kraken maybe it fucked up environment vars

livid kraken
#

I dont think so since the sanity check of building with a fresh project passed

plucky laurel
#

so something somewhere is cached

livid kraken
#

Yeah but where🤣 I cleared all caches I can think of

plucky laurel
#

and nothing in source control?

#

potential places, EditorPrefs (?), ProjectSettings, package manifests or something

livid kraken
#

Nope git is clean

#

Well was clean, after the lib nuke not so much

#

Anyways Im at the doctors now so wont be working on this anymore at least for today

#

Maybe I will come back and it will work🤣

plucky laurel
#

"after the lib nuke not so much" what how

#

should not be tracked

viral flicker
urban sequoia
#

Range checks

#

Button timing

#

Relative position to the other player

undone coral
undone coral
#

it's possible that installing a windows update "cleaned up" your system environment variables, where there was previous an issue with them there is no longer such an issue

#

and consequently you now have a lot more of e.g. your JAVA_HOME or PATH correctly working

#

and it's finding your other android sdk path there (or something)

#

the windows update might also be a red herring, you may have just not restarted in a while and something else you installed or updated modified your PATH / JAVA_HOME / ANDROID_SDK_PATH or whatever that path is

tidal maple
#

how can i load a dll at runtime and run it's main script?

sly grove
undone coral
tidal maple
undone coral
#

you can look at the XMage or Spellsource source code to see how to represent something like a card game card in json

tidal maple
#

thx

sly grove
tidal maple
#

k

#

btw, is there a way to not run malicius code and only code that game want?

sly grove
#

Nope

#

😛

#

that's why this is so dangerous

#

there's no way to know what the Assembly it going to do

tidal maple
#

then i'll make a system to review it before you can use it XD

sly grove
sly grove
#

that's why a lot of mod support uses languages like LUA which can be plugged into your game and limited on what parts of the application it has access to

tidal maple
#

have an example on how i can use LUA?

sly grove
#

it's a LUA engine for C#. Basically you can create lua functions that call back to C# functions you write

#

letting you define your mod api into your game

tidal maple
#

that's perfect

#

but if someone wants to add a custom model or UI?

sly grove
#

so the modder would write LUA, which only allows them to call C# functions that you have predefined basically

sly grove
tidal maple
#

k, will it work with prefabs too?

sly grove
#

wdym

tidal maple
#

if someone wants to add a prefab

sly grove
#

you'd have to provide support for that somehow

tidal maple
#

k

sly grove
#

e.g. via AssetBundles

tidal maple
#

i'll invent something

undone coral
tidal maple
#

thx for the help guys

golden saddle
#

I'm getting an InvalidOperationException when I call SetResult() on a TaskCompletionSource. I've verified that that both the TCS and the argument are instanced and of the appropriate type. I'm kind of at a loss on how to troubleshoot this.

#

I'm also not calling SetResult from anywhere else - 1 shot.

sly grove
golden saddle
brave solstice
#

my enemy is broken 😭

#

can someone tell me why hes not attacking/chasing player

fresh salmon
brave solstice
#

so I tried to put debug logs, and its not even showing that hes put into the attack mode. seems like hes stuck on idle

#

I got the nav mesh stuff already setup

sly grove
brave solstice
#

i put them in jusst about every if statement i could that said somthing about attack

sly grove
#

I don't see any in the code you shared

brave solstice
#

oh cuz i deleted logs before share sry

sly grove
#

you'll want to put them where the state transitions are supposed to happen

#

you want to figure out if it's never geteting into that state, or maybe it's getting into that state and quickly exiting for example

#

and then figure out why

brave solstice
#

can u help me figure that out, show me where to put them?

coral blade
#

@brave solstice one way to make things more organized is things like

state = InitStateAttacking()
public AIState InitStateAttacking
{
    anim.SetBool("IsAttacking", true);
    return AIState.Attacking;
}

and then your if statements can be like

if(EventAttacking()){}

instead of

if(distanceToPlayer <= attackRange)

for example.

your AI state machine is just ultra simple logic based on distance so it should be easy enough for you to figure out just looking over the code.

for me I found it extremely helpful to print the state every time it changes, so you have a better idea of what is going on

#

organizing it like it said is really helpful because you may have to paste things in multiple locations otherwise, and then make a change on one and forget the other

brave solstice
coral blade
brave solstice
coral blade
#

does PlayerPos return transform.position

coral blade
#

great

brave solstice
#

had to fix my patrol points

#

TYTY

#

😄

coral blade
#

np

brave solstice
#

somtimes i want to throw my keyboard 😅

coral blade
#

yea same. I find the best way to solve my problems is to calm down or rest up

frozen prawn
#

How would I go about getting the class that called a function? I'm trying to make a custom logger, and I'm calling it from a class called TestErrorCaller,
however, running this code:

Debug.Log((new System.Diagnostics.StackTrace()).GetFrame(1).GetMethod().DeclaringType.Name);

returns <>c__DisplayClass10_0, and not TestErrorCaller

flint sage
sly grove
#

so it's printing the name of the type
why not print the name of the method itself?

flint sage
#

Oh call, not sure that is possible easily

#

Creating a new stack trace is probably very slow

sly grove
#

oh sorry I misread

frozen prawn
#

Method name works, trying to get the class from which that method is called

#

but it's returning something weird and not the class which it is called from

#

if it's not possible it's fine I can probably pass the type as an argument

#

just trying to do this from a code cleanliness perspective

sly grove
frozen prawn
#

looks better to call Error("blah") instead of ErrorFromClass<TestErrorCaller>("blah")

frozen prawn
sly grove
#

Is it inside a lambda or something

frozen prawn
#

OH

#

sheisse

#

yea it is

sly grove
#

yeah that's the name of the lambda class

#

that was created automatically by the compiler

frozen prawn
#

hm

#

ok yeah might need to work around that

#

ty for the help

undone coral
#

a logger shouldn't do reflection

#

you will get an exception

#

in your logging code

#

and pull your hair out in anger

#

usually the simplest thing is

class MyMono : MonoBehaviour {
 private static readonly Logger logger =
  LoggerFactory.GetLogger(nameof(MyMono));
}

@frozen prawn
but you shuld just use microsoft.logging

atomic warren
#

Help

#

this is the error

#

its an unity script not mine

#

and the code... without errors?

sly grove
atomic warren
#

yhea

sly grove
#

because that code is clearly broken

atomic warren
#

its the psdImporter

sly grove
atomic warren
#

i was testing put } or ;

#

because that is what the description says

#

but nothing more

sly grove
#

uninstall/reinstall the package

#

and/or uprade it to the latest version

brave solstice
#

is this the way to call my input func to attack?

#

this is in my animcontroller.cs ``` public void Attack()
{
anim.SetTrigger(AnimationKeys.Attack);
}

public bool Attacking()
{
    return anim.GetCurrentAnimatorStateInfo(0).IsName("SwordAttack");
}```
#

so im trying to access that by using my input on the attack script

#

to trigger my animation attack layed out in my other script

mint python
brave solstice
brave solstice
#

getting this error now

#

still spitting error after i put animator = GetComponent<Animator>(); in awake

mint python
brave solstice
brave solstice
#

@mint python so this correct?

mint python
brave solstice
#

where can i put a debug log?

#
     if(!isAttacking)
     {
       animator.SetTrigger("Attack");
       Debug.Log("Attacking pen!");
         StartCoroutine(InitilizeAttack());
         
     }```
#

here?

zenith ginkgo
#

Are you sure this is an advanced topic

brave solstice
#

@mint python this is my input

lusty egret
#

hey guys, so Im having this error for no reason, I just imported taro dev's .unitypackage:
https://github.com/Matthew-J-Spencer/Ultimate-2D-Controller
and its giving me this error:
Assets\Tarodev 2D Controller_Scripts\PlayerExtras.cs(14,24): error CS0106: The modifier 'public' is not valid for this item
(basically for every thing that has public in the script)
here is the script:
https://gdl.space/ejogihadik.cs

GitHub

A great starting point for your 2D controller. Making use of all the hidden tricks like coyote, buffered actions, speedy apex, anti grav apex, etc - GitHub - Matthew-J-Spencer/Ultimate-2D-Controlle...

sly grove
sly grove
#

remove public from all of the interface members

#

in both interfaces

lusty egret
sly grove
#

they are public

#

automatically

#

that's how interfaces work

#

I'm talking only about lines 14-19 and 23-24 in that script

#

nothing else needs to change

lusty egret
sly grove
#

IExtendedPlayerController

#

i told you exactly which lines

lusty egret
#

sorry about that, its fixed

#

thanks allot 💙

grim oxide
#

I have a project, I want to break some of the systems into separate code libraries so I can use them in other games and more easily update and so on. How does that work in Unity? 🤔

#

I remember seeing some file extension I can't recall now when looking at a code asset from the store 🤔

grim oxide
#

Is that the same thing? 🤔

sly grove
#

no

grim oxide
#

Models, Textures, animation and audio clips
, and other assets.

#

Does that include prefabs? 😮

#

Oh these are probably the same format asset store stuff uses huh

#

Are there any strange performance concerns with using interfaces on monobehaviors? 🤔

grim oxide
#

Cool neurodSit

compact ingot
#

they are just often useless without custom tooling/inspectors because unity can't deal with them in serialization and the inspectors

grim oxide
#

🤔 Can't you assign components to interface fields in the inspector?

#

Could swear I've done that

compact ingot
#

nope

#

unity needs a concrete type for everything it is supposed to serialize (i.e. all serialized fields that you assign in inspectors)

grim oxide
#

Is there something else that is used instead?

#

GetComponent takes interfaces right

compact ingot
#

yes

#

you can use the [SerializeReference] attribute to get some sort of interface serialization but you should be very careful when you use that, its not a general solution

grim oxide
#

So what is the solution for loosely coupling two packages? 🤔

compact ingot
#

loose coupling is not achieved by just using interfaces

grim oxide
#

That much is now clear :p

#

What are the alternatives, so far my experience with Unity has been there's usually some workaround to the quirks lol

compact ingot
#

you could just use a regular base class to define the interface

grim oxide
#

True, that bypasses the issues?

compact ingot
#

you can also still use interfaces, just not for the automatic inspector fields

grim oxide
#

Well, it doesn't matter if it 'forgets'

#

The base class thing makes enough sense

compact ingot
#

the whole UI EventSystem is built on top of inetrfaces and base classes

#

you could look at that for some ideas

grim oxide
#

Oh well the base class thing means... hmm it's still fine, but you have to have an extra component involved

#

Instead of just slapping the interface on the component that is interacted with

#

But that's nbd

compact ingot
#

in most games full decoupling of systems is frequently impossible

#

or at least impractical

#

it just adds a lot of code that does nothing and that is rather difficult to make efficient or makes debugging quite tedious

grim oxide
#

I mean, code assets existing disagrees with that a bit

#

I'm just trying to break up, for example, an inventory system from a FPS character controller from a stat-buff system

compact ingot
#

yes, but why do you need interfaces for that?

grim oxide
#

I don't, base classes sounds fine

compact ingot
#

you wouldnt even need inheritance

#

you just make the code flow in a decoupled way

grim oxide
#

I mean, sure, I might end up not needing it at all, just establishing my options before I even start thinking about how to separate it

compact ingot
#

and assets like UniTask or DOTween or Mirror are anything but decoupled

grim oxide
#

Nah I'm talking stuff like a dialogue system

compact ingot
#

thats also not decoupled at all

grim oxide
#

From what? dayHmm

compact ingot
#

you will not be able to replace dialogue system X with system Y

#

you will design your game to suit the dialogue system asset, that is not decoupling

grim oxide
#

🤔 I am not referring to coupling with the game, but with the other packages

#

Obviously at some final level things gotta have glue 😛

compact ingot
#

what good is a dialogue system that does not cooperate with your UI juice or Behaviour Tree asset?

grim oxide
#

Optional cooperation is the goal. Keyword being optional

compact ingot
#

good luck with that dream

grim oxide
#

I'm pretty sure you're just misunderstanding what I'm talking about 🤔

grim oxide
#

I just don't want them to require each other explicitly

#

That's not that complicated 🤔

#

Code assets optionally work with other code assets fairly often

#

Without requiring them

compact ingot
#

you'll see how pointless these assets often are, precisely because they each do their own thing and don't integrate holistically

grim oxide
#

Using... existing code... is pointless... got it lol

#

If you can't write the code needed to glue stuff together then sure

#

But using existing code libraries is like 99% of programming

#

Pretty much just when you are learning do you write software that uses 0 existing libraries

languid latch
#

Anyone here have expert certs? I'm interested in knowing how hard the test is.

sweet pine
#

i'm trying to lerp from quat1 to quat2 but it gets flipped, i tried both euler and quaternion but result is same

// Extra points
for (int i = 0; i < genPts.Count; i++)
{
    float blendValue = ConvertRange(0, genPts.Count, 0.0f, 1.0f, i);
    var rotationFrom = start.localRotation;
    var rotationTo = end.localRotation;
    var localRotationBlend = Quaternion.LerpUnclamped(rotationFrom, rotationTo, blendValue);
    var base_left_angle = localRotationBlend * Vector3.right;
    var base_right_angle = localRotationBlend * Vector3.right;
    var leftPos = genPts[i] + -base_left_angle.normalized * length;
    var rightPos = genPts[i] + base_right_angle.normalized * length;

    genExtraPts.Add(leftPos);
    genExtraPts.Add(rightPos);
}

more details and a minimal github repo is presented here https://gamedev.stackexchange.com/questions/202180/how-to-lerp-correctly-between-two-unlimited-rotations

result :

untold moth
sweet pine
untold moth
sweet pine
untold moth
#

Well, anyways, the point is that you shouldn't rely on the values in transform. Especially if you're using values above 360(possibly 180). It gets converted to a quaternion and clamped back to the above-mentioned values. Thus, you'd need to define your rotation separately. If you need to include the current local rotation offset you could get it from the local rotation Euler angles and add to whatever value you want to be above 180/360.

barren stump
#

Say I have a white floor, with a character that can move left and right. How do I make it so the colour of the floor is yellow on the sides of the screen, and then gradients into white at the center of the screen?

#

The player can move left and right, but the floor will still follow this colour pattern?

sweet pine
untold moth
untold moth
barren stump
#

Not very familiar with that. I’m sorry I’m kind of new to unity and didn’t even know there were shaders lol. Do you think it would fulfill my purpose? And does it work in 2D?

barren stump
sweet pine
#

i got a solution in my mind to create a temporary game object set the position and apply the rotation using transform.Rotate and set it back to points but it will be a performance killer no?

untold moth
jolly token
untold moth
untold moth
sweet pine
#

it's a simple spinner script

public class Spinner : MonoBehaviour
{
    public float speed = 0.0f;
    void Update()
    {
        transform.Rotate(transform.up, speed);
    }
}

spins the start/end points

untold moth
#

Okay. Well, instead of rotating the transform, just accumulate the value as a float and use that in your other script. If you do need to rotate the "spinner" object as well, you could feed the accumulated rotation into it as well.

#

The point is to keep your angles rotation stored as an angle and not as a quaternion

#

Float can be swapped with a Vector3 if you need to rotate around more than 1 axis.

float speed;
float currentAngle;

Update()
{
    currentAngle += speed * Time.deltaTime;
}
jolly token
# barren stump Not very familiar with that. I’m sorry I’m kind of new to unity and didn’t even ...

https://www.ronja-tutorials.com/post/039-screenspace-texture/
Something like this but in your case texture would be simple gradient

sweet pine
untold moth
#

Mathf.Lerp(currentAngle, targetAngle, t)

#

Then use the result to construct a quaternion from Euler angles and use that as the new rotation.

#

Perhaps that's not the only issue with your current implementation. But it's definitely on of the issues.

sweet pine
untold moth
twin belfry
#

I apologize if this more so belongs in #💻┃code-beginner but I feel like it might be a fairly complicated thing im trying to achieve. Currently, I have a 3D FPS game that im working on. I'd like to incorporate a funny gun, where if you shoot another player with it, you and them must battle to the death in a game of PONG. I'm trying to think of the best way to achieve something like this and I'm not sure what's possible. My plan is to set the current camera of the players to a camera somewhere far away and have a 3d pong game playing there? Is there maybe some sort of canvas or UI I should use instead? Sorry its a very general idea, but any advice would be helpful!

jolly token
#

What happen if multiple user use that pong gun at the same time?

twin belfry
jolly token
#

I mean anything is possible if you can manage it properly..

twin belfry
#

perhaps too complicated for a newbie like me lol

jolly token
#

But the basic idea of setting camera somewhere far is probably right. You could do it with layer but it will be complicated.

jolly token
#

No problem!

trail cloak
#

Hello there;

#

I noticed there is this OnCanvasGroupChanged() function under the UIBehaviour class

#

Is there a fast way to obtain the CanvasGroup that invoke this method?

#

Oh.... there is implementation available in the Selectable class

flint sage
#

Singletons make a lot of things a lot easier in exchange for some mess if yuo want to do some more complicated things

#

Like threading

#

If you never run into those problems then they can make code a lot cleaner because well, you don't have to architecture systems that solve those problems and have less perceived complexity

upbeat path
#

Take Code Monkeys claims with a pinch of salt, imo his code is generally neither good nor clean.
That said the singleton pattern is very useful because it can cut down on a lot of .Find and .GetComponent calls which can hurt performance

novel plinth
#

GetComponent is not as slow as you'd imagine, as a matter of fact it still extremely fast... One awesome folk at c# discord server did a benchmark between IL2CPP vs Mono GetComponent

#

lemme screencap and drop it here

#

it's faster than Dictionary lookup

upbeat path
flint sage
#

Yeah I remember that convo

#

Seemed not trustworthy

#

Also cached getcomponent vs uncached is very different

novel plinth
#

It might, but the dude who wrote that seems trustworthy enough at least to me 👀

devout hare
#

Making reliable benchmarks is very hard. Any number of things can invalidate the results.

upbeat path
#

Thats because there is no data nor software design in the stuff. It's programming by stream of conscience which is always a bad thing

silk sable
#

But I like going in programming hyperspace where the one who sees all tells me the whole program structure. That transe is the fun part

upbeat path
#

Thank you, I'm glad that at least one person understands the correct way to make software

#

That is a talent which, unfortunately, cannot be learned, you either have it or you do not

silk sable
#

It ends up as a pile of garbage, though the process is fun

#

That's the stupid way of learning programming

#

seeing the design problems AFTER you're 50 hours into a project and have to scrap it

upbeat path
#

Yes, the worst kind, thinking they know everything when, in fact, they know nothing

#

That is also very true, but usually practiced by people who shouldn't be in the industry in the first place

#

The worst trap of all is not knowing the technical requirements of the system you are making. You cannot write Application code like you would Game code and, conversly, you cannot write Game code as you would Application code

#

That is the problem, 'It kinda works', so they do not learn nor do they try to do it better

unkempt nova
#

Happen to have a link to an intro on hexagonal architecture? Looks interesting

upbeat path
#

you are missing the point, in game software we have the FPS monkey sitting on our backs, in most other applications that is not so. If you really want to see optimal data/software design you need to look at the financial world where nano seconds in software count

wet sail
#

can someone tell me whats wrong with this gameloop i implemented ?

private void MainLoop()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            long stepTime = stopwatch.ElapsedMilliseconds; 

            while (!_quit)
            {
                _deltaTime = (stopwatch.ElapsedMilliseconds - stepTime) * 0.001f;
                stepTime = stopwatch.ElapsedMilliseconds;

                _frame++;
                if (!_paused)
                {
                    Update(_deltaTime);
                }

                var dt = (stopwatch.ElapsedMilliseconds - stepTime);
                if (dt < frameMilliseconds)
                {
                    Thread.Sleep((int)(frameMilliseconds - dt));
                }
            }
        }

when i set the frameMilliseconds to 1000/300 (300fps)
the fps jumps from 333 to 250 abnormally. why ?

silk sable
#

My two cents is, Games also tend to be very object oriented by nature, everything exists by itself, whereas when I design other software, it's mostly centralized, with less parts. So I need to think more about the design pattern for the game so that the objects interdependency is scalable and workable.

sly grove
wet sail
flint sage
#

You do realize this is a Unity server and not a game engine development server?

upbeat path
upbeat path
# wet sail why not

If I have to tell you the difference between int and float you should not be writing code like this

wet sail
#

frameMilliseconds and dt are not floats, they are long

flint sage
#

Stopwatches are also not that precise depending on the platform

#

Because they're backed by different things

wet sail
#

i dont think a jump from 250 to 333 consistently is caused by that

#

there's a bug somewhere

flint sage
#

well, if it's never hitting your target FPS then your precision is likely wrong

#

Caused by stopwatch, thread.sleep and possibly other things

upbeat path
flint sage
#

And that

wet sail
errant plinth
#

What happens if you use a busy loop instead of Thread.sleep? Does the same behavior persist?

wet sail
upbeat path
#

so dt == 0

errant plinth
#

A TimeSpan expresses a time period in 100 ns ticks. Research what methods can return a time span may yield some ideas

upbeat path
#

look at your code
stepTime = stopwatch.ElapsedMilliseconds;

wet sail
#

yeah it wont be 0

#

bc there is milliseconds that happen going through update() etc..

upbeat path
wet sail
#

wym subtract actual time?

sweet pine
wet sail
#

didnt understand that part

upbeat path
# wet sail wym subtract actual time?

say you want a fixed delta of 200. the time from the last frame is 0.9, the update takes 0.1 so your sleep period is (fixedDelta - (actualDelta + updatetime)

sweet pine
flint sage
#

He's not doing unity so your suggestions don't make sense

sweet pine
#

wait a minute, this channel is not about unity?

fresh salmon
#

The whole server doesn't make sense if they're not using Unity

#

This channel is about Unity

flint sage
#

That guy is just off topic

sweet pine
#

bruh

lavish sail
#

moment

wet sail
sweet pine
# wet sail yeah limiting fps. wym high ratio fos

high ratio fps is like rendering a empty scene which gives 2000fps
now add a single triangle and it drops to 1000fps
so we get 1000FPS drop but it doesn't mean if you add another triangle it drops 1000fps
FPS is not linear

wet sail
#

yeah sorry guys didnt have any other server to ask my bad

sweet pine
upbeat path
wet sail
#

so you saying never learn?

#

alright thanks anyway

lavish sail
wet sail
#

im doing that rn by asking 🤷

sweet pine
# wet sail so you saying never learn?

Drawing a circle wrongly a thousand times will not make you a master of drawing perfect circle, you need to learn the logic before you start coding,
I usally bring everything down on paper before start coding

errant plinth
#
  1. Go native
  2. Find high precision timing structures for your target hardware platforms
  3. Write your own scheduler
  4. Have fun
wet sail
upbeat path
lavish sail
#

you can also use notepad instead of paper

upbeat path
maiden turtle
#

does anyone have a library or at least a console app in mind that would describe a unity project (all asmdefs and all dependencies), or generate the project and the solution files for each project, outside the unity editor?

#

The least I need to generate the project files without starting up the editor and clicking a bunch of buttons

plucky laurel
#

it is what is generating the project afaik

#

so in theory you can copy it and modify

maiden turtle
#

you mean calling methods by name?

#

thing is, the package may not exist in the cache

maiden turtle
#

I realize that generating the project files without restoring the library folder with the package files is a tall order

#

it would effectively mean reimplementing their pipeline

regal olive
#

hello. Im trying to create an optimization system, its quite simple.

#

atleast thats what i hope

obsidian glade
undone coral
untold moth
sweet pine
untold moth
#

I'm trying to upload it now.

untold moth
jolly token
#

SourceTree was cool back ago. Now Fork is the best git gui imo

sweet pine
#

thank you dlich, this is amazing! changes you made twist the points perfectly! it becomes so cool by playing with speeds...

however this is not like the reference i need, it shouldn't twist it just have to comeback to same state it started rotation.

hallow elk
#

Which is more optimal for firing a delayed method: Invoke(nameof(methodName), someFloat) or a coroutine with yield return WaitForSeconds?

hallow elk
#

Ok, cool. THanks

#

Here's a fun one. I am trying to make a dictionary with two variables as a key. Unsure how to do it. Essentially:

A, B | AB
B, A | AB
A, C| AC
C, A| AC
B, C| BC
C, B| BC```

Is there a better way to do this?
jolly token
#

Use a ValueTuple

sly grove
#

ValueTuple is not order agnostic so it won't work

jolly token
#

Oh you want retrieve value regardless of key order

#

I would just sort the key lol

sly grove
#

ew - wasteful

hallow elk
#

On second thought, I might not need it to be order agnostic. Here's the sitch:

I have a variable defined that is an object's 'material'. Not Material, but a generalized one (stone, wood, etc.) When two objects collide, I want to take both objects 'material', and check it against a dictionary of sounds to play the right collision sound. But it occurs to me that dropping a rock onto a metal table sounds different than dropping a spoon onto a stone table

#

So I assume that makes it a bit easier. In which case, maybe valuetuple is the place to be

sly grove
#

a regular tuple would do fine

#

ValueTuples are mutable, which you don't need

sage radish
#

(int, int) tuples are compiled as ValueTuple anyway, no reason to use ValueTuple directly.

jolly token
#

I wouldn't want to allocate for dict lookup

sly grove
#

tuples are structs

jolly token
#

System.Tuple is class

sly grove
#

you have to jump through hoops to get that

#

(int, int) x = (5, 3);

#

is not a Tuple.Create

jolly token
#

That is, ValueTuple you just created

sage radish
#

The tuple language feature in C# translates to ValueTuple now. It used to be System.Tuple.

sly grove
#

fair enough

obsidian glade
jolly token
#

I don't recall tuple syntax ever being System.Tuple.

sage radish
jolly token
#

It introduced in C# 7.0 and it was ValueTuple ever since

#

.NET is very strict for backward compatibility as well

#

Only "breaking" syntax change I know is capturing loop variable into closure

undone coral
#

however i think you prboably want to create a

class SoundProperties {
 ...
}
scenic sage
#

I want to make my own custom render engine that shoots out raycasts at each pixel and detect if it hits a certan object. allowing the rays to bounce on geomitry. How can i get a world raycast for a given pixel on the camera?

#

This is fairly simple so i dont want to make my own shader for this

#

And how can i set a pixel on the camera to whatever I need?