#archived-code-advanced

1 messages ยท Page 162 of 1

steel moss
#

i COULD think that they have some plugins which is proprietary

#

and they just have no legal permission to open it

#

if so - then cringe

regal olive
#

I could think their codebase is littered with unknown stuff they don't want public, like API keys or whatever

steel moss
#

why would use 3d party solutions in public engine

regal olive
steel moss
#

but again, make like Autodesk with Stingray Engine - they added support to C++ plugins with public headers

regal olive
#

I think they would. Unity can't monetize services if people can fork their own engine and YEET themselves away from unity

steel moss
#

why Cryteks and Epic Games then doesnt loose it?

regal olive
#

Because it isn't an MIT level license

steel moss
#

exactly like it was with XRay engine

regal olive
steel moss
#

My idea is what we make games, not mods, engine must be flexible enough to do whatever and how i want

flint sage
#

It is flexible enough

steel moss
#

Lol no

flint sage
#

You can still do the same things you want just not in the way you are currently stuck in

steel moss
#

Can i make custom placeable entity with custom icon in the world?

flint sage
#

Yes

regal olive
#

Lol

#

Just not in the way you would prefer to

flint sage
regal olive
#

Why?

steel moss
flint sage
#

No engine is going to be flexible then

steel moss
regal olive
flint sage
# regal olive Why?

Because it's a discussion whether an engine is flexible or not, not advanced coding concepts in Unity

steel moss
#

Basically, EVERY engine with open C++ code IS flexible, cuz i can just rewrite its part

regal olive
flint sage
#

I'm not going to have a meta discussion about the topic of this conversation

flint sage
steel moss
#

Also you will not argue about performance loose with a bridge between (C++ <-> C#) native and managed code

#

its just poor dessign

regal olive
steel moss
#

we have luajit which speed MUCH better then C#

flint sage
#

Scripting languages in engines are not just about speed

steel moss
#

and Lua can just call any C function without performance lost

regal olive
flint sage
#

No one is making you use Unity, if you don't like how it works the ndon't

steel moss
flint sage
#

No it's not

regal olive
flint sage
#

In 99% of the cases you don't need perfect performance, besides lots of cpp games have shit performance

regal olive
#

They're the same architecture -- a byte code language on top of C++

steel moss
#

30 fps on RTX 3060

#

and 3950x

#

while we have 200fps with same config in BF5

#

how that was happening?

regal olive
#

A Language does not automagically grant good or bad performance. It's up to the programmer

flint sage
#

You're comparing apples and pears

steel moss
#

I mean, there is a good solution

#

if you dont want to open C++ code, add luajit support

#

its speed only 2 times slower then C

flint sage
#

Well, that's slow af

#

Why would I use that?

steel moss
#

and 10 times faster then c#

flint sage
#

I'll just write asm, thanks

regal olive
#

They have... instead of LUA they use C#. It's the same architecture

steel moss
#

Yep and slowing all system with this

#

its ok, i am just arguing for diversity

regal olive
#

Wait... is this just an elaborate troll?

steel moss
#

some would stay with C# and Burst which is not usable for projects like Tarkov, some will use lua which is perfect for that

steel moss
regal olive
#

@steel moss I have an idea... add a LUA interpreter to the C# space of unity.

steel moss
#

๐Ÿ™

#

๐Ÿ’ฉ

#

that what it would be xD

regal olive
steel moss
#

Also luajit is compiled time, regular lua would be slow

steel moss
regal olive
#

๐Ÿคฆโ€โ™‚๏ธ

#

Why don't you make some utilities to make your life easier if you want to develop in unity?

fresh salmon
#

That evolved into a meta conversation about how Unity isn't good enough, isn't it

regal olive
#

If you want to use unity like source, make it happen. Hide the ugly unity bits behind your own abstraction.

steel moss
#

Its about Unity Technologies does not support diversity

regal olive
#

๐Ÿคฆโ€โ™‚๏ธ

fresh salmon
#

Yeah, so it's still meta, and not on-topic with this channel anymore

regal olive
#

I still disagree with that sentiment. This feels very much on topic for this channel

steel moss
#

Me too

#

๐Ÿ‘

regal olive
#

I also am frustrated by the convo because it doesn't seem like you are willing to work with the limitations of this game engine. Why?

fresh salmon
#

Thing is, if you don't like how Unity doesn't support diversity, then... just don't use it lmfao

#

Switch to Unreal or Source or whatnot

regal olive
#

Or make an abstraction in unity that works like how you want it to

steel moss
#

I dont use it, my company works with Source

fresh salmon
#

Then why do you come complaining about it here

#

That makes no sense

#

It's like how I would go to a supermarket I've never been to before, and yell in that they suck because they don't have the same aisle arrangement as the one I'm used to

steel moss
#

My sister is learning game dev with Unity and asked me for help, i tried... You know what happened next with GameObject inheritance

regal olive
#

@steel moss why don't you teach her a game engine you are familiar with? Or... learn this game engine. You seem capable.

Did you get embarrassed when you couldn't do the basic thing in unity in front of your sister?

fresh salmon
#

I think you're just trying to teach her Unity, but your other engine architecture experience is scrambling that up

#

She can just follow the beginner tutorials

steel moss
regal olive
#

Maybe let her learn unity on her own, and maybe later she can teach you

steel moss
#

๐Ÿ™ƒ

crude moat
#

what is this error supposed to help me ๐Ÿ˜‚

compact ingot
crude moat
#

ok thanks

flint sage
#

There's probably another error or more in the description (usually is at least)

compact ingot
#

i've seen that error show up all on its own

crude moat
#

there ain't, otherwise i wouldn't ask here

flint sage
compact ingot
#

current LTS as thats all that I use (current as in, at the time it was the current LTS)

flint sage
#

I only ever see it if I'm doing some dll stuff

compact ingot
#

yes, only happens when messing with external things

#

or on a new project with lots of assets/packages/libs added in bulk

regal olive
#

how to make variable

regal olive
#

jk

hybrid plover
#

I have a pooling system of arrows, When I shoot an enemy the arrow sticks in that enemy and the enemy gets destroyed after a few seconds. This obviously also destroys the arrow stuck in the body. The problem is that when I get to that arrow again in my pool, I get a nullref because that arrow doesn't exist anymore? Ofcourse I could do a nullcheck but after a while my pool gets empty. I could expand my pool but that just delays the problem.
How can I detach my arrows before they get destroyed? Can I add a script to the arrow with OnDestroy method and unparent it there? I read that once Ondestroy is called you can't unparent it because it will get destroyed anyway? Any tips?

cedar saddle
#

instead of parenting the arrow you could use a follow behavior I think

#

or you could detach before destroying

hybrid plover
#

Thanks! But wouldn't that detach all children? I have a completely skinned character so if i detach children before destroying, all other objects would also be detached?

hybrid plover
hybrid plover
#

Yeah I should note that my arrow has no script attached to it. It is purely a visual gameobject. So the only way to do that is if I check each child in the parent, look for the name 'arrow' and then detach that object. But it seems a bit overkill or so I don't know.

#

But I just found that there is a parent constraint component made by unity so I'll check that first ๐Ÿ™‚

#

thanks for the help!

undone coral
#
/ Check if caster has enough mana to cast the spell.
        if (eventData.Caster.Stats.Mana < eventData.Ability.ManaCost) {
            Debug.LogFormat("Invalidating {0}", eventData.Ability.Name);
            eventData.Log.Add("Not enough mana!");
            eventData.Invalidate();
        }

this is bad

unkempt nova
#

Why's that?

undone coral
#

also, these methods are not IEnumerators / cannot handle player choices or time

#

or async

#

you probably have something of the form

#
spell:
do something
put an object in a list somewhere

time passes

player makes a choice
pop this object off a list somewhere
resume casting spell
#

this is also bad

unkempt nova
#

No, I don't

undone coral
#

hmm

#

so what happens when stuff takes time

#

when casting a spell

unkempt nova
#

Nothing yet, haven't got that far

undone coral
#

got it

unkempt nova
#

What's bad about what you quoted?

undone coral
#

it should be knowable statically if something can be cast or not

#

mechanics that make something possibly not castable after you try to cast it, or vice versa, are cantankerous

#

you'll never write those

#

but the burden of that possibly happening will show up in a million places

unkempt nova
#

The TryCast is mostly for UI

undone coral
#

right, the UI should just show statically what can and cannot be cast

#

the player shouldn't have to try pulling a card in their hand / pressing an ability button to discover if they do or don't have enough mana

#

how would you render a green rectangle around the ui element if you don't know statically if it's castable due to mana?

#

statically means, you can just look at the game state, you would not need to push an event

#

and give other stuff the opportunity to run code

unkempt nova
#

Fair point. I was thinking more in terms of silencing auras, things like that

undone coral
#

a silencing aura would put an attribute / tag / whatever on something that says, "silenced"

#

so that you can resolve it statically

#

you wouldn't want a silencing aura to work like

model EVERYTHING as an event
the player tries to do something
  run a bajillion pieces of code
  \with uncertain interactions
  one of those happens to be a silencing aura
    it's a tries to do something event
    check if there is an ...
    touch a million things to prevent the player
    \from doing something ...
#

it's really complicated

#

just

#
player cant' do something because it
has silenced on it
unkempt nova
#

Hrm. That does make sense. I do intend to have silence auras give you a buff when in range

#

I like the idea of tags. Might do that for buffs

undone coral
#

oops

#

i fixed it

unkempt nova
#

Just feels too coupled to me, sounds like pain

undone coral
#

it is painful

unkempt nova
#

Just me trying to understand an event bus I've never used

undone coral
#

the events stuff makes stuff

#

because text in RGPs and magic-the-gatherings are "triggers"

#

and you need to do something because you do something else

modest lintel
#

Has anyone managed to get the logs from unity on iOS player that isn't built from your system and hence not attachable to xcode? Is it even possible? Google says no.

undone coral
#

they're not a good way to model the whole game

unkempt nova
#

Well, I need triggers and reactions eventually, like MTG

undone coral
#

the best way to model the whole game is to just write it in code

#

write the code that does the thing

#

if you're like, well how do i deal with a player making a choice, that's what async (best) or IEnumerator (better) is for

#

because you'll find even in magic the gathering, which has 19,000 cards or whatever

#

that can be expressed in code

#

there's a lot of stuff they never do

#

so you never need something so flexible

#

and then, even with the weird stuff, it's better to special case it

#

because you might print only one card that does this 1 weird thing

unkempt nova
#

Yeah I'm not sure I agree there

#

I see where you're coming from though

undone coral
unkempt nova
#

I have no idea where you pulled card game from, but cool

undone coral
#

yes it sounds like an ARPG style game right?

unkempt nova
#

Yep

undone coral
#

i think you might have a very fixed number of reasons that an ability cannot be used - CANNOT_USE_ABILITIES, not enough mana, and no targets

#

which can be determined statically from the game state, and would not need to evaluate rules

#

and this will make your user experience better

#

whereas, if you permit a rule - really a triggered thing, this event bus - to decide if a player can use an ability

#

which sounds right doesn't it?

#

you will make everything way more cantankerous

#

if something needs to prevent an ability from being usable, it should shove CANNOT_USE on it

unkempt nova
#

Yeah I'm not sure I'm gonna use the TryCast and Cast. Was more doing it because it seemed like a good way to get acquainted with the Event Bus

undone coral
#

i think use the event bus idea as minimally as possible. introduce events and triggers to implement specific text

#

and make it async while you're still ahead

#

before you write all this stuff

#

because the game is going to get extremely painful to write if you don't deal with the fact that text doesn't deal with ticks but your game engine does

#

or whatever small unit of time you choose to do

unkempt nova
undone coral
#

i'll write an example - is the game working like an ARPG / MOBA?

#

are those the kinds of abilities we're talking about?

unkempt nova
#

Yeah

undone coral
#

so let's say it's an ability with the text

Deals 150 damage over 3 seconds in a radius
unkempt nova
#

Yeah, already have some of those. Definitely makes sense for async there

#

I just don't get what you mean about text

undone coral
#

ideally, you'd want to implement this ability this way

protected override async Task<Ability> Cast(ICastingArgs castingArgs) {
  var position = new PlayerChosenPosition(castingArgs).position;
  var duration = new DOTTime(seconds: 3);
  var frequency = new DOTFrequency(timesPerSecond: 4);
  var damageLeft = new DOTDamageValue(150);
  var targetingSpec = new RadiusTargetingSpec(position, this.radius, Filters.ALL_ENEMIES)
  var result = await GameContext.instance.DoDOTDamage(
    duration, 
    frequency,
    damageLeft,
    targetingSpec);
}
#

but new DOTTime and new DOTFrequency... would probably need to come from a factory

#

you want the text written the ability to appear in your spell implementation

#

and you want to deal with, what if the damage is buffed inside DOTDamageValue

#

because that's really complicated!

unkempt nova
#

Ah, yeah, I'm doing something similar. Currently using coroutines as a placeholder. Using ScriptableObjects essentially as factories (from my understanding of the pattern) they actually create a new Ability object for each cast, so player stats, etc can be accounted for

undone coral
#

DOTDamageValue looks like

class DOTDamageValue {
  int textValue; // 150
  int DamageToDeal(DOTFrequency freq..., duration) {
    var unbuffedAmount = textValue / (freq * duration)
    textValue -= unbuffedAmount;
    return GameContext.instance.Buff(unbuffedAmount) ...
  }
}
unkempt nova
#

Luckily for me, no filtering necessary though

undone coral
#

does this make sense?

#

you eventually want a piece of code to look like the text

#

you don't want it all abstracted away

#

if you can't find a piece of code that "looks" like the text, it's painful

#

it's really painful to turn text from ARPGs and card games, which are already algorithmic, into data structures

#

that's just a shittier C#

#

if your text doesn't look algorithmic, that's also bad!

#

that means the ability is written poorly

#

all of this stuff comes together

#

why async? because then you can use cancellation token

#

or any number of tokens

#

to deal with the bajillion ways something might be interrupted or changed

#

and do it in ther ight place

#

for example, it shouldn't concern that specific DOT ability if the player is silenced

unkempt nova
undone coral
#

DoDOTDamage should do the damage over time, but using a decorator (a function wrapping the damage over time rules) that deals with silencing, the player dying... etc.

undone coral
unkempt nova
#

Oh, the ability description?

undone coral
#

yep

#

Deals 150 damage over 3 seconds in a radius

unkempt nova
#

I gotcha

undone coral
#

this is already algorithmic!

#

you should write these first anyway

#

before you program anything

unkempt nova
#

Yeah, I see what you're saying

undone coral
#

at least a few

unkempt nova
#

I already have them all, actually, so that's sorted

#

Mostly, anyway

#

You're right though, it is very helpful having all of that info ready before coding

#

Being able to skim through and see obvious requirements helps a lot

undone coral
#

i would start with

#

what is the most comfortable way to putting the text into code

#

it's probably not by dragging and dropping stuff into the unity inspector

#

a lot of people think it is

#

for some reason

#

i am personally most comforted by finding functions that say what the text says as closely as possible

#

you will want to "factory" the numbers and effects in the text, as types, and use the implicit/explicit casting to make it easier to use

#

so instead of

var damage = 5

you definitely want

DamageValue damage = GameContext.instance.CreateDamageValue(5);
unkempt nova
undone coral
#

async can be painful because it has this cancellationtoken thing

#

that you gotta really master

#

because a ton of gameplay will interact with it

unkempt nova
#

Makes sense

undone coral
#

you want to factory these values because, for example, they may need to be buffed and have references to state, or because you might want to attach a description to it for a tooltip, etc.

unkempt nova
#

Exactly, yeah

undone coral
#

okay cool

unkempt nova
#

Well, cool. Thanks for the advice. Will keep it in mind. Gotta go though. Later

foggy dew
#

Im working on a 2d top down game. Im trying to implement solid principles i just learned. Is this good practice

solid roost
#

dont think u can

#

theres this tho

humble onyx
#

you can change the camera speed but not sure if that works for the zooming

regal olive
#

I'm trying to do some digging to find out if there's a solution for my issue. I just want to disable certain hotkeys so they do not work in play mode.

plucky laurel
regal olive
#

In my case I don't want Ctrl+S to work because so many games use that with crouching + walking backwards

#

and if I do it, it just spams save errors in play mode

plucky laurel
#

seems that chasing solid is premature

hot tendon
#

hey im trying to update a mesh but im wondering if theres a way to update a part of a mesh quickly without resending the whole mesh back to the vertex buffer

plucky laurel
foggy dew
plucky laurel
#

combat system implies a system

plucky laurel
#

this is not a system this is a component of some kind with a specific purpose

#

start with single responsibility principle, an attack is not a collider

#

a collider is a dependency of an attack

#

study virtual methods

#

drop the idea of learning solid, its useless to you at this point, focus on simply writing logically cohesive code

foggy dew
#

What I do is wrong with meleeattackcollider script? I am aiming for dependency injection by creating it

#

as I said before in the future of this project maybe i would like to attack by layer

plucky laurel
#

what dependency injection

#

you dont understand what im saying

raven jewel
#

why does List.Contains always return false?

plucky laurel
raven jewel
#

wdym?

plucky laurel
#

follow the logic :

  1. It actually does work for literally everyone, as it always did.
  2. If it doesnt work for you, you dont provide any information so assume people are telepaths
#

so, how can anyone answer your question

raven jewel
#

why the hostility?

plucky laurel
#

im not hostile

#

just because i am correcting you doesnt mean im hostile

raven jewel
#

also there isnt more knowledge needed. if i have a list and i do list.contains(obj) it always returns false.

past harbor
#

Then obj must not be in your list. Do you have an example? I use it all the time

plucky laurel
#

there isnt more knowledge needed

raven jewel
#

my boi over here bein hostile

shadow seal
#

Tbf your question was crap

plucky laurel
#

you can keep trying to paint me hostile, or you can agree that your question was unanswerable and finally provide code

shadow seal
#

It's obvious that your List does not contain the thing you want, the method is working as intended

#

With no more info, that's the answer

raven jewel
#

i see

#

i will check somewhere more useful then.

shadow seal
#

They will say the same thing

#

This method is working as intended

plucky laurel
#

Some people learn their lessons the hard way

raven jewel
#

sounds like reddit in here

plucky laurel
#

Because reddit people like to act all logical? Programming is about logic, nothing strange that people operate on it.

urban warren
#

The only reason that .Contains(..) would not return the object, is if you have overridden the Equals(..) method for the object and did it wrong/in some way that they don't equal

raven jewel
#

equals method?

#

im just doing if(list.contains) do code

#

it says it returns a bool

urban warren
#

If you don't know what it is then it is safe to say you didn't override it ๐Ÿ˜›

#

Try adding the object before checking if the list contains it. That will tell you that if the Contains(..) method is finding the object or not

raven jewel
#

that isnt the issue. im checking if a list has a string before it adds the string

#

but it always returns false

urban warren
#

There may be something that you think is inconsequential so omit, but is actually very important

raven jewel
#

it sounds odd, but im not a big fan of showing my code cause it sucks

urban warren
raven jewel
#

well, thanks anyway

plucky laurel
#

@raven jewel Yeah, and that is the reason why you called me hostile, server non useful and compared it to reddit, its not because we are what you say, its because you are defensive or have another reason that you don't reveal.

#

And its ok, no judgement.

raven jewel
#

my point was more to your phrasing and such. for instance, i thought mantistobboggan and mech were real nice and professional while you came off as something stuck up your ass

#

and i still get that impression because you still are on about it

plucky laurel
#

I am just blunt. I am voicing whats on the mind of most.

raven jewel
#

so did mantistobboggan and mechwarrior99 and yet they were nice about it and not stuck up

#

but i cant teach you manners

plucky laurel
#

You are doing it again, my hope is that you see that its simply innefective.

regal olive
plucky laurel
#

sounds incorrect, provide an example?

regal olive
regal olive
plucky laurel
#

I can write my own DI container

regal olive
#

Excellent. If you know that, then you should be able to reason out how accessing components on a game object is a form of DI

plucky laurel
#

sounds incorrect because the gameobject here acts as a local service locator and not an injector

foggy dew
regal olive
#

That's getting a bit into the weeds into implementation details, lol.

plucky laurel
#

those are different principles

regal olive
#

o...okay.

#

Anyways, yea when I realized that get/set component API was a form of DI it really cleared things up.

#

Well. Shit. @plucky laurel is right. Hell yea, I can improve my vocab. I've been chunking both concepts in the bin of "DI"

#

Although, I suppose to get real technical. SetComponent is DI and GetComponent is SL

plucky laurel
#

i also spent some time thinking and you are right in some aspect, you can use gameobject as di container, because it has type resolver,
however even if we think of it as container, as soon as you do

void Awake(){
  GetComp<IFoo>

you are coupling the object to the container, which is volation of the ioc, which makes it not di

regal olive
#

Yea... It doesn't fit any definition very well. I think that's a side effect of the weirdness of game programming, to go on a limb. ๐Ÿคทโ€โ™‚๏ธ

I'm a programmer interested in writing tests for my code. For me, I just see a game object as a weird way of injecting mocks or spies into a monobehaviour for analysis

plucky laurel
#

is there any framework for that?

regal olive
#

Like... honestly I wish I had read a good analysis on what exactly a game object is in relation to DI/inversion of control. I haven't really found one (which is why I enjoy convos like these!) so I am left to synthesize knowledge from other sources (DI:principles, practices, and patterns) and work my brain into making things make sense

regal olive
# plucky laurel is there any framework for that?

I use vanilla unity testing tools and build my own abstractions around it.

I haven't spent time noodling on how to add nuget dependencies to a unity project. I've seen people version control DLLs in their projects which isn't an option for me because I work publicly.

regal olive
# plucky laurel is there any framework for that?

Writing a mock or a spy or any test fixture is pretty easy. When I do have the benefit of nuget, I usually reach for NSubstitute.

Is this answering your question? I may be missing the mark and wanted to check

alpine adder
#

anyone have experience using unity command line or a ci/cd within unity particularly regard arkit

#

will literally pay you to help me solve my problem lol

plucky laurel
#

this is a rabbithole, ill cease my mental gymnastics

regal olive
regal olive
alpine adder
#

hmm im currently set up in Jenkins already

regal olive
#

@alpine adder the creators have exposed docker containers for consumption, though that's more advanced (especially those w/o container knowledge)

#

One sec, getting a couple URLs

alpine adder
#

hmm we are also using bitbucket

#

which adds another stupid layer

plucky laurel
#

abstracted myself into a corner many times with painful refactors, the opposite is also true. I cant outline any concrete guidelines i follow, i think my brain factors in things like future points of extension, volatility of the thing, duplication, complexity (if i dont abstract it here, how easy it will be to abstract later, if easy then whatever), taking designer needs into account, probably more factors. But since i dont enforce it on myself and in none of my gamedev commercial experiences ive encountered any project big or small that adhered to something completely on the level FizzBuzzEnterpriseEd, i feel pretty good if time investment/tech debt/KISS are balanced. @regal olive

regal olive
plucky laurel
#

yeah im on the side - weight all factors and decide is it really necessary, basically.

regal olive
#

@alpine adder using bit bucket/Jenkins shouldn't be a huge barrier. As long as you have the CI/CD webhook starting Jenkins jobs. You'll have to add a step to run some docker commands, based on code you can reverse engineer from the GitHub actions.

It'll take some translation! I recommend getting started by building your project locally using docker.

plucky laurel
#

gamedev is such a mess generally

regal olive
regal olive
regal olive
plucky laurel
#

when i encounter people who are deep into dod/verbose ecs i feel at a loss, i feel like im stuck on oop/"a thing" thinking

#

think i have to invest time into low level stuff at some point

alpine adder
#

Iโ€™ll have to check it out

#

Im sure people on that discord could help out in general

regal olive
#

https://youtu.be/YtROlyWWhV0

This video helped me conceptualize OOP and right levels of abstraction

Explore DDD 2019 - Denver, Sept. 16-20

Object-oriented languages have opinions about how best to arrange code. These opinions lead OO to naturally offer certain affordances. Just as round doorknobs expect to be grasped and rotated, OO expects messages, polymorphism, loose-coupling, and factories. The key to creating intuitive and maintainable O...

โ–ถ Play video
alpine adder
#

Maybe less on the docket and server side stuff

#

But we all have to code in unity command line for this

#

And create a build file in editor

regal olive
#

@alpine adder what are you trying to do, in a couple sentences?

alpine adder
#

Enable ARKit through the manager plugin api so that when we build for iOS ARKit exists and is linked

#

here is a thread i made

hushed fable
#

There are C# as a build file solutions

#

Like Cake and Nuke

#

You can get pretty much completely C# driven pipeline if you want to

alpine adder
#

well so most of it is a completly c# pipeline

#

its the unity side thats failing

regal olive
alpine adder
#

yup thats exactly how im doing it

#

we call the static class or method from the buildscript in the editor folder

#

its the plugin management code to turn on arkit thats not working

regal olive
#

I wonder... When you import that plugin via the package manager locally, is there an additional set you have to do?

Example: when important text mesh pro, you then have to unpack it into your project. Is there a step like that for ar kit?

alpine adder
#

hmmm

#

not that im aware of

#

the step is to click the little arkit button support in xr-plugin-management

#

which is what the code in the thread aims to do

regal olive
#

Okay. If you don't click that little arkit button locally after installing the package I wonder if you could recreate the issue on your local machine.

By the way, everything works when you build locally, yea? I figure yes but I also don't want to assume

alpine adder
#

yes. if i don't click the little button i get the same errors

#

but if you look through the build script and say re-open the engine after running the build script it does look like the little button is enabled

#

although it doesn't seem to act like itburn2

regal olive
#

Gotcha. Here's what I would do. Assuming this package has at least some parts open source, I would reverse engineer whatever C# script backs whatever that button press represents

#

Let me see if arkit source is on unity's GitHub

alpine adder
#

nope thats exactly what im talking about

#

the code you see above is doing what it wants through the script

#

but thats not whats working

#

and hense the errors

regal olive
#

This might be the source code: https://github.com/U3DC/Unity-ARKit-Plugin

The editor script that defines what all happens should be in there. My hypothesis is you may be missing a call to something in your build script

GitHub

This is a native plugin that enables using all the functionality of the ARKit SDK simply within your Unity projects for iOS. - GitHub - U3DC/Unity-ARKit-Plugin: This is a native plugin that enables...

#

Shoot me over a screenshot of that button and I can try finding the file

plucky laurel
#

@regal olive thanks for all the food for thought

alpine adder
#

maybe code is in here

undone coral
#

i'm confused why you have to do this at all

#

i build an android ARCore app and ios ARKit app from the codebase and i don't have to touch this stuff

#

the build script just works with BuildPipeline.BuildPlayer

alpine adder
#

it is an app that has arkit

undone coral
#

i don't understand why you have to "turn on ARKit" programmatically

#

what am i missing

undone coral
#

are you not checking in some asset files or setting or something?

#

are you trying to build this not on a mac?

#

i have build automation working just fine

#

i'm using com.unity.xr.management@4.0.1

undone coral
alpine adder
#

so im building it on a server. I check the box manually but still have issues for some reason

#

so i wrote this code to do it automatically

#

as a fail safe

undone coral
#

i don't understand

#

i am also building it "on a server"

#

i get what your goal is

#

but what is really the thing you're working around here

#

because if it's checked, it's checked

alpine adder
#

i still get linker errors though

undone coral
#

on a linux build server?

alpine adder
#

mac

#

its just a mac mini

#

with a port forwarding

undone coral
#

have you tried downloading the project and running it on this mac mini

#

opening the project

alpine adder
#

yup

undone coral
#

and building it on this device?

#

and it works?

alpine adder
#

yup

#

when it builds locally its fine

undone coral
#

are you using BuildPipelines

alpine adder
#

but going through my script it has linker errors and arkit does not generate in xcode

#

im using jenkins. but the build script which is what unity handles is roughly the same

undone coral
#

i think this checkbox is a red herring

#

i'm saying are you using UnityEditor.BuildPipeline.BuildPlayer

alpine adder
#

correct

#

BuildReport buildReport = BuildPipeline.BuildPlayer(scenes, targetDir, buildTarget, buildOptions);

undone coral
#

have you tried building this on unity cloud build

alpine adder
#

I have not. at least not in a year

undone coral
#

your build script can be really simple. is it? you sort of have to get rid of all this other stuff

#

i would try making a super simple script

#

and try running it on unity cloud build

#

and see what happens

#

jenkins is ase_dead

alpine adder
#

that is true

undone coral
#

lol

alpine adder
#

the original use for Jenkins was so we could run builds when creating prs

undone coral
#

there are a bajillion things that could be wrong with a jenkins build agent

alpine adder
#

unity cloud build only runs after a pr goes thorugh

undone coral
#

i don't know. is this a lightship project?

alpine adder
#

we have others i set up that are

undone coral
#

is this the only one using ARKit?

#

also, are your development machines all macs?

#

and when you open the project on the mac mini, does it make changes to any files in the tree?

#

you might be .gitignore -ing a file that you need, that's generated by the editor

#

i am leaning on this being a smaller issue than a bigger issue

#

it sounds like you're doing everything right

#

i think maybe you just make well-named branches for unity cloud build and work aroun dit

#

like staging-1 staging-2 staging-3 ...

#

so it goes.

alpine adder
#

hmm we develop on windows mostly which is why our server is a mac. the tree idea is interesting i havn't checkked yet

#

and yeah ill see what cloud build does

#

maybe its worth the switch over

undone coral
#

it's not really possible to develop ios apps on windows

#

it's a bankrupt idea

#

have yout ried building a unity xr sample

#

with your script?

alpine adder
#

i have not

#

but also great idea

regal olive
# undone coral jenkins is <:ase_dead:473833740188254218>

Jenkins is a standard in the CI/CD industry. It's a big name. A lot of businesses use it. I prefer github & gitlab actions myself, but I've set up a jenkins server in a docker container before. I enjoyed watching how it evolved.

#

it's not really possible to develop ios apps on windows

I'm on my desktop now. I'm going to test this hypothesis using the game.ci docker container. I hypothesize this is correct, and one would have to use a OSX based image to build the production artifacts. We shall see for sure shortly

alpine adder
#

try some arkit for me ๐Ÿ˜„

tall pebble
#

Hey anybody know if there's a way to subscribe to Unity Roadmap updates? I used to subscribe to the old rss feed, but they don't seem to be updating it anymore

misty glade
#

Not really a Unity question, but there's some bright folk in here, and this is probably one of those "fun" problems that.. I can't seem to dream up an elegant and time-complexity fast solution for.

I have a list of missions in a "bag". Each has a weight (integer, typically 100-200). I'd like to draw an item from the bag randomly where the odds of drawing out any given item are the item's "weight" divided by total weight of the bag. My solution is not good, but hopefully illustrates the problem:

(In this example, AvailableMissions is a dictionary<guid, int> where the key is just an identifier and the value is the integer weight.)

            int weightTotal = AvailableMissions.Sum(x => x.Value);
            Guid drawThisMission = Guid.Empty;
            foreach (KeyValuePair<Guid, int> kvp in AvailableMissions)
            {
                int thisRand = NumberUtils.Next(weightTotal); // 0-999 for 1000 total weight, eg.
                if (thisRand < kvp.Value)
                {
                    drawThisMission = kvp.Key;
                    break;
                }
                weightTotal -= kvp.Value;
            }

I presort the bag from highest-weight to lowest weight to minimize the iterations here on average, but obviously this is a pretty poor solution. I'm not even sure if it's correct.. It seems to be?

A quick google yielded no obvious algorithm/heuristic for this, and yet, I feel that in the game dev world this has to be a solved problem. TIA.

olive cipher
#

Hey, so I am converting a class to a byte[], send it over the network and convert it back to the class on the other end via marshalling. I am now facing problems sending arrays. I tried following attributes for the array:

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
    [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]
    [MarshalAs(UnmanagedType.ByValArray)]
    [MarshalAs(UnmanagedType.LPArray)]

ByValArray crashes the receiving end, LPArray gives following error: Structure field of type Int32[] can't be marshalled as LPArray

Code references for the marshalling functions and my full class im sending:

[NetworkPacket, StructLayout(LayoutKind.Sequential)]
public partial class SamplePacketData : INetworkPacketData
{
    public float Time;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
    public string Name;

    [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]
    public int[] Test;
    public string Testing;
}

// Marshalling
        // TData = SamplePacketData
        static byte[] StructToByteArray(TData obj)
        {
            int len = Marshal.SizeOf(typeof(TData));
            byte[] arr = new byte[len];

            IntPtr ptr = Marshal.AllocHGlobal(len);
            Marshal.StructureToPtr(obj, ptr, true);
            Marshal.Copy(ptr, arr, 0, len);

            Marshal.FreeHGlobal(ptr);
            return arr;
        }
        
        static void ByteArrayToStruct(byte[] buffer, ref TData obj)
        {
            int len = Marshal.SizeOf(typeof(TData));

            IntPtr i = Marshal.AllocHGlobal(len);
            Marshal.Copy(buffer, 0, i, len);
            obj = (TData)Marshal.PtrToStructure(i, typeof(TData));

            Marshal.FreeHGlobal(i);
        }
olive cipher
#

Nvm, im stupid, i forgot to set the MarshalAs for the string after the array, which crashed the marshalling

mild laurel
#

Why I get this error?
error CS0236: A field initializer cannot reference the nonstatic field, method, or property Settings.PatcherSettings.environment'`

thin mesa
#

because you are trying to access something that isn't static in a static context. Assign the field in Awake/Start. Or ask in #๐Ÿ’ปโ”ƒcode-beginner

drifting galleon
undone coral
# misty glade Not really a Unity question, but there's some bright folk in here, and this is p...
IEnumerable<int> CumulativeSum(this IEnumerable<int> items) {
  var i = 0;
  foreach (var x in items) {
    i += x;
    yield return i;
  }
}

var weights = new List<int>() {20, 50, 10, 100, 30};
// O(n)
var ranges = weights.CumulativeSum().ToArray();
var total = ranges[ranges.Length - 1];
var rand = UnityEngine.Random.value * total;
// ๐Ÿคฏ O(log n) lookups
var i = ~normalized.BisectSearch(rand);
// O(n)
weights.RemoveAt(i);
#

this way you do not have to sort anything, so it's O(n) instead of O(n log n)

#

once you've computed the weights once, you can draw in O(log n)

#

this is fine, because getting the probability directly by calculating the multinomial hypergeometric has a combination in it that is O(log n) anyway

misty glade
#

I understood some of those words.

#

๐Ÿ™‚

undone coral
#

lol

#

i just looked this up

#

to see if it was possible to do this faster

#

i don't think you can

misty glade
#

I will have to dissect that a little bit further - I think that's where I was going as well, and when I realized I was reading some research papers and code written by donald knuth I knew I was pretty far down the rabbit hole

undone coral
#

this one is pretty simple

#

in the grand scheme of things

#

you eventually need a cumulative sum

#

so it will be no better than O(n)

misty glade
#

A couple of problems - I will often be pulling items out of the bag, and also incrementing weights (they're not fixed), so I may potentially lose savings on the draw operation by the .. uh.. initial operation

undone coral
#

but since a cumulative sum is sorted, you don't need to sort

#

that's okay

#

you can't beat O(n)

#

that's fine

misty glade
#

I saw something about the binary search tree population

undone coral
#

you can sort of optimize the cumulative sum. but it will still be O(n)

#

i wouldn't sweat that part

misty glade
#

Yeah.. I worry about this a little bit because I think the game designers intend to have several hundred missions so... performance might actually matter

undone coral
#

i mean you can optimize the cumulative sum even after removal

#

but it's not worth it

#

it wont' matter

#

because it's randomly chosen

#

so it will still be O(n)

misty glade
#

O(n) for the draw operation? or the population operation?

undone coral
#

O(n) is if you calculate the cumulative sum every time

#

whichi think you have to if you always remove it

misty glade
#

I thought there was a method here with relatively modest space complexity that could do the draw operation in O(1)

undone coral
#

it's unavoidable

#

the draw is O(log n)

misty glade
#

hm... I feel like there has to be a nifty way to recalc in less than O(n)

undone coral
#

there ain't

#

but think about it... removing an item from an array at random is O(n)

misty glade
#

I wonder if I could do something really fast in less-than-perfect manner

undone coral
#

no

#

you are already doing O(n)

#

because you're removing from an array

#

you can remove from a map, sure

misty glade
#

dictionary removal ops are O(n)? i thought they were O(1)

undone coral
#

but then it's not sorted

#

they are

#

i don't think it gets better than this

misty glade
#

hm..

#

my brain is too tired to search for better i think

#

and TBH this is getting into the realm of .. "if i try to optimize this in a manner I don't thoroughly understand the bugs that arise are going to be very difficult to find and fix"

#

so I perhaps should just leave well-enough alone

undone coral
#

yeah

#

it won't matter

#

this is the best one

misty glade
#

hehe ok thanks for looking

#

fun little problem regardless

undone coral
#

lol

#

there's no cumulative sum update that is better than O(n) in the general case!

#

it's impossible

storm wave
#

Kind of an interesting problem I am facing. I was wondering if there is a way for an object (gun in this case) to point to what is in the center of the main player camera, because I thought it might be an interesting effect for my first person shooter. I've drawn up this diagram thing to help explain that maybe I could use angle D to adjust the guns rotation, but I have no clue how I would go about doing this. The gun is a child of the Main Camera.

undone coral
#

๐Ÿ… you have my seal of approval

misty glade
#

hey

#

stop editing that

undone coral
#

lol

misty glade
#

i'm trying to read it ๐Ÿ˜›

undone coral
#

i was annotating it

misty glade
#

lol

undone coral
#

you are maybe overthinking this

#

you can just do

transform.LootAt(worldSpacePositionOfCursor);
transform.up = Vector3.up;
misty glade
#

i think i can do better than O(log N) in recalcing the weighted sum, btw, IF i accept less than perfect precision

#

but I don't know that I can prove this, just a gut feeling, and i'm not sure what the loss in precision would be

undone coral
#

if you could somehow touch N values with less than N touches

misty glade
#

lol

#

point is they don't have to be perfect

#

just sort of good enough

undone coral
#

we're hiding a sort in there

#

that's why it works

#

you're beating O(n log n)

#

cumulative sum gives you an array of sorted values

#

any other optimization would require sorting the weights first, which is O(n log n)

#

so cumulative sum is already the hottest in town

#

cumulative sum giving you sorted values lets you use binary serach on the lookups

misty glade
#

true but my operations are always exactly "remove one item" or "add one weight to every item" and i feel like those could be .. cheated somehow

undone coral
#

you can do

remove i...
update all items i...n - 1 with -= value[i]

but it's still O(n)

#

and it DOES affect the probabilities (logically)

#

because you removed something out of the bag

#

so you can't just be fuzzy about it

misty glade
#

hm

#

that makes sense, but i'm still going to think on this overnight or in the next couple of long showers

undone coral
#

you can't just skip it because then you'll reroll on aveage the number of items you've removed

#

which adds up to... O(n)

#

no dude you will be trying to bend quantum spacetime

misty glade
#

haha

undone coral
#

and invent a wormhole into the past

#

if you figure this out

misty glade
#

well i'm certainly not bright enough to do that

#

๐Ÿ™‚

undone coral
#

lol just thinking about it makes me

#

want to crawl into a wormhole

misty glade
#

but i am juts wondering how i can fuzz the data or sorting to get "good enough" randomness at vastly improved performance

#

like imagine the degenerate case with an infinite number of items with equal weight

#

if i draw one out, recalculating every item in the array is infinite time

#

and yet the odds of each/any of them being drawn on subsequent draws is virtually the same

undone coral
#

you'd have to know the sum of the weights anyway

misty glade
#

so.... there seems to be some way to get to about that performance without recalcing

undone coral
#

eventually you need the sum

#

you can't beat it

misty glade
#

once, yes, but not on every draw (unless the randomness needs to be exact, which it doesn't)

undone coral
#

it will always be O(n)

#

you can reduce your precision of the weights, but you'll only get an improvement if you reduce the precision by O(log n) at least

misty glade
#

the position?

undone coral
#

such that at least n - log n elements or more go from having different weights to the same weight

misty glade
#

ah

undone coral
#

do you see how that is a big cheat? that's saying you want to turn n elements into log n elements

misty glade
#

maybe i'll just tell the game designers all missions have identical weight

#

๐Ÿ™‚

undone coral
#

so you can go from

10 11 9 10 3 5

to

1 1 1 1 0 0
#

reducing the precision

#

and now, that appears to be

1 1 0
#

does that make sense

misty glade
#

not sure i follow..

undone coral
#

okay

#

lemme make a better example

misty glade
#

but I can't chat atm - just putting kids to bed

undone coral
#

lol

#

okay

misty glade
#

(and then i gotta hit the hay myself)

#

but... I think I'm understanding enough to see that i'm not going to really improve on the example above

undone coral
#

the point is, you can do "make these items be the same", and roll twice - once to select from a reduced set of items, and then another time within items of the same weight

#

that's the fuzzy part

misty glade
#

and that smarter people than me have spend a lot of time on this uh.. CDF? cumulative distribution function?

undone coral
#

but in the process of fuzzing it down, you will have visited every item!

undone coral
#

3 F 2 is really expensive to calculate

#

guess what you have to do to calculate 3 F 2? a sum*!

#

it's unwinnable

drifting tusk
#

I am trying to recursively go through every child object and save & set their material to a single new material, but when this runs- all the children object seem to just get a generic new material instead of the single one I make at the start with fullCoverageMat

    public void SetShader(Shader newShader) {
        fullCoverageMat = new Material(newShader);
        ChildInChild_SetAllMats(transform);
    }

    private void ChildInChild_SetAllMats(Transform parent) {
        foreach (Transform child in parent) {
            Renderer rend = child.GetComponent<Renderer>();
            if (rend != null) {
                storedMats.Add(child.gameObject, (Material[])rend.materials.Clone());
                int matCount = rend.materials.Length;
                rend.materials = new Material[matCount];
                for (int i = 0; i < matCount; i++) {
                    Debug.Log("Setting material");
                    rend.materials[i] = fullCoverageMat;
                }
            }
            ChildInChild_SetAllMats(child);
        }
    }
undone coral
#

@misty glade even if you binary tree sorted the cumulative weights, then tossed weighted coins on your way down the tree

#

deleting could wind up making the tree height n

#

its' unwinnable

drifting tusk
austere jewel
#

materials is a copy of the array

undone coral
#

@misty glade you can use this

#

this will be O(n log n) once you've deleted every item, which is as good as you will do.

#

this beats my O(n^2)

#

you won this time @misty glade

drifting tusk
# austere jewel materials is a copy of the array

Yeah... I kind of figured that would be an issue later I also need to solve. But currently, a little stuck on just setting the materials when I set renderer.materials to a new array w/ each material set to a single reference of fullCoverageMat

austere jewel
drifting tusk
#

I haven't gotten back to the resetting of materials, but this is the entirety of messing with the materials

    public void ResetMaterials() {
        ChildInChild_ResetMats(transform);
        storedMats = null;
    }

    private void ChildInChild_ResetMats(Transform parent) {
        foreach (Transform child in parent) {
            if (storedMats.ContainsKey(child.gameObject)) { 
                Renderer rend = child.gameObject.GetComponent<Renderer>();
                rend.materials = storedMats[transform.gameObject];
                ChildInChild_ResetMats(child);
            }
        }
    }

    public void SetShader(Shader newShader) {
        fullCoverageMat = new Material(newShader);
        ChildInChild_SetAllMats(transform);
    }

    private void ChildInChild_SetAllMats(Transform parent) {
        foreach (Transform child in parent) {
            Renderer rend = child.GetComponent<Renderer>();
            if (rend != null) {
                storedMats.Add(child.gameObject, (Material[])rend.materials.Clone());
                int matCount = rend.materials.Length;
                rend.materials = new Material[matCount];
                for (int i = 0; i < matCount; i++) {
                    Debug.Log("Setting material");
                    rend.materials[i] = fullCoverageMat;
                }
            }
            ChildInChild_SetAllMats(child);
        }
    }
austere jewel
#

every time you call rend.materials it makes a copy

#

so you are assigning an empty array to the renderer

drifting tusk
#

oh, oh ๐Ÿคฆโ€โ™‚๏ธ

austere jewel
#

and then iterating and making matCount of copies, each with only one material assigned to them

drifting tusk
#

So my initial problem is that I am using a copy instead of source

cunning flame
#

Why is my coroutine doing this? I was having the same issue with Async the force value is jittering. maybe the issue is the lerp? pls @ me

drifting tusk
serene folio
cunning flame
#

The truncation with the int is intentional if that what you mean

ancient talon
#

I suggest using Mathf.RoundToInt() in your division comparison.

remote drift
#

Is there any way to do this?

#

it says I can't ref inside anonymous method

orchid marsh
compact ingot
remote drift
#

hm, what if I do unsafe

#

and instead of ref I pass pointer

#

will that work?

#

assuming I never write to that struct

#

I only read from it and change it's internal fields

#

bruh

fresh salmon
#

Can't do unsafe because structs are unmanaged.
And try without an anonymous delegate, use a method that has a ref parameter.

compact ingot
# remote drift bruh
        private void Register<T>(ref T act)
        {
            T captureAct = act; // this is a local variable that can be captured by the delegate closure
            Action performed = () =>
            {
                captureAct.pressed = true;
            };
        }
remote drift
#

not to referenced struct

compact ingot
#

if you donโ€™t want that, donโ€™t use closures or ref

remote drift
#

I'm simply trying to reuse code here

#

as otherwise I'm forced to write same method for each action

#

it worked like a charm when I didn't have to register callbacks sadkek

#
    private static void UpdateAction<T>(ref T action, ref bool state) where T : struct, IInputAction
    {
        if (action.Active)
        {
            if (state)
            {
                state = false;
                action.Active = false;
            }
            else
            {
                state = true;
            }
        }
    }
#

this works for every action

compact ingot
#

you could use regular methods

remote drift
#

wdym?

#

oooh

#

damn

#

I can simply use same struct

#

lol

#

damn it, I'm pepega

#

ok, it still leaves me with inablity to use ref in anonymous

#
    private unsafe static void RegisterAction(ActionComponent* action, InputAction input)
    {
        input.performed += _ =>
        {
            action->Pressed = true;
            action->Active = true;
        };
        input.canceled += _ =>
        {
            action->Pressed = false;
        };
    }
#

hmm, I wonder if it's safe

fresh salmon
#

Then use a method instead of a delegate, for the 3rd time

remote drift
#

I can't pass struct reference to that method

#

without writing code for each of those structs

fresh salmon
#

Yeah, and the parameters wouldn't match anyway

remote drift
#

but, maybe it'll work with pointer

fresh salmon
#

Pointers are unavailable for unmanaged types (structs)

#

But, why a struct in the first place anyway?

remote drift
#

because I can't have managed types

#

in jobs

fresh salmon
#

Ah, I see

#

I'm afraid it's not possible then

#

Also, as regular structs can contain managed types, I would suggest changing the generic constraint from struct to unmanaged

remote drift
fresh salmon
#

No, because structs don't live on the unmanaged memory (the heap)

remote drift
#

hm, I believe it's not true

#

because I saw some Unity code

#

I actually used some unity code

#

that uses struct pointer

fresh salmon
#

Well, Collider is a class

#

So an instance of it lives on the heap

remote drift
fresh salmon
#

Unity.Physics? Now that's a namespace I don't know about

#

They're not the same as the regular Collider component

#

From UnityEngine

#

No idea then, good luck!

regal olive
#

What's a good way of making something in unity that has super poor performance characteristics?

I'm instantiating, waiting a frame, deleting, and doing that. It's the exact opposite of object pooling. The GGC kicks in after a while and I can see it all happen in the profiler. This works but I'm sure there are plenty of other ways.

I'm trying to flesh out common ways to make under performing unity software. There aren't many guides since most want to steer folks towards good performance. I want to break things

humble leaf
#

Using Find operations each frame, on multiple objects will be a sure way to kill performance.

sly grove
alpine adder
#

im back

drifting galleon
#

or find a prime

regal olive
misty glade
#

@undone coral I'll still need (want?) to wrap my head around the implementation for this and implement it in C# anyway, but this looks like exactly what I was looking for. O(log n) worst case!

#

My python is a fair bit rusty as well (embarassed to say)

compact ingot
misty glade
#

using Razor

#

๐Ÿ‘€

regal olive
#

I'll see though!

compact ingot
orchid saddle
#

I am trying to do a cone of area damage. My parent transform does not rotate and it is 2D, so I handle the rotation on a child gameObject. Though I have noticed that local directions are a little weird. I drew a line with "transform.TransformPoint(Vector3.forward)" and the line works as intended. However, calculating the angle seems to not work properly:

Transform target = col.transform;
Vector3 targetPos = (Vector2)target.position + (target.GetComponent<BoxCollider2D>().offset * 2);
Vector2 directionToTarget = (targetPos - transform.position).normalized;

Debug.Log("Angle " + Vector2.Angle(transform.TransformPoint(Vector3.forward), directionToTarget));
#

If anyone knows a better way to do a "cone" of damage on a local object or if I am doing something wrong, that would be great! I am trying not to enable and disable a collider a bunch of times and would rather do a OverlapCircleAll and check the angle as I am trying to above

sly grove
#

typically "forward" in 2D is either transform.right or transform.up depending on how your sprite is drawn

#

transform.forward is typically "into the screen", along the z axis

orchid saddle
# sly grove `transform.forward` is typically "into the screen", along the z axis

Yes thats what I thought too, but my object must be rotated weird or something to do with the local directions. Ive been trying to switch to dot since that seems to be how most people do it. I seem to have got the below code working:

float cosAngle = Vector2.Dot((inputPoint - (Vector2)this.transform.position).normalized, this.transform.forward);
float angle = Mathf.Acos(cosAngle) * Mathf.Rad2Deg;
Debug.Log("Angle is " + angle);
return angle < 70;
sly grove
#

selected, and amke sure your tool handle rotation is set to "local"

orchid saddle
#

For sure, one sec

#

And I am trying to do an aoe damage within a certain angle.

#

Here is my player. The purple particles rotate to follow my mouse position. The cyan line is the transform.TransformPoint(Vector3.forward) and red line is transform.right. That triangle collider is where I want the damage to be. It seems like the new dot function that I added is working as intended

#

The red line transform.right barely moves, it just moves left and right a tiny bit. Even doing full circles around my player with my mouse

sly grove
#

red should be to the right

#

and blue should be into the screen

#

you should fix your object hierarchy and rotations

#

(I'm assuming you're in 2D mode?)

orchid saddle
elder jacinth
#

Hiya, quick question, with the SpriteRenderer component, how does it allow my to select a file from the project files? more acurately, where would y'all say is a good starting point for researching that whole thang haha, thanks! I need to use asset files so that I can do a preset style function fyi, thanks again!

sly grove
#

Then you can drag and drop it into your SpriteRenderer or UI Image component

elder jacinth
#

oh sorry, i should've said, i mean so that I can do presets for like, weapon damage/effects, i used the sprite renderer as an example of selecting an asset from the projects, my bad!

#

lemme show you my setup one sec, i'll thread it so as not to spam

uneven sorrel
#

Hi folks. I created a 2D level editor for my students (for NES Metroid and Zelda levels) a couple years ago. One of the things it does is export a PNG of the entire map via byte[] bytes = Texture2D.EncodeToPNG() and File.WriteAllBytes(path, bytes);. This worked very well last year and the year before, but now, when I run this in the Unity Editor on macOS, the debugger runs through this code fine, but then my entire Mac freezes (apart from the mouse), and I must restart. (It appears to work fine on Windows.)

My assumption is that this is due to the macOS's new restrictions on accessing the drive and that somehow Unity is restricting me from seeing the message where macOS is asking if it's okay to access the drive. If it makes a difference, I'm attempting to write to the Desktop in my own user folder. Alternatively, I would be happy to copy the image to the Clipboard, but copying an image to the Clipboard also seems to only work in Windows.

If any of you have suggestions or thoughts on the issue, I would really appreciate it. Thank you in advance.

cobalt sphinx
#

It might be where the file is being saved if the current user has the correct permissions to perform full RWXC abilities there or not. When you debug where does it get stuck at in the code?

#

As in when does it become non responsive

harsh cedar
waxen elk
#

im curious how old are yall

harsh cedar
#

what does this have to do with advanced coding

cobalt sphinx
#

Bot or troll shrug.

undone coral
undone coral
cobalt sphinx
#

in fact, just doing everything but writing the file will tell you if it is a permission level issue.

uneven sorrel
# cobalt sphinx It might be where the file is being saved if the current user has the correct pe...

Strangely, it completes all of my code in the save function and then becomes unresponsive, which leads me to believe that writing to disk is an asynchronous task. So, in this code (https://pastebin.com/0hR6eDf2) the debugger exits SaveTextureToFile() before the computer halts.

cobalt sphinx
#

Disc writes are always async depending on when then OS finishes the task. That's why we used to have the save to eject stuff for USB

uneven sorrel
#

(Sorry for the delayed response. I was taking care of my toddler.)

uneven sorrel
uneven sorrel
cobalt sphinx
#

Windows won't prompt you it will just fail to create a file or edit

#

Do a check if the file exists before hand maybe? I'm not too familiiar with MacOS I just compile code there for iOS

uneven sorrel
uneven sorrel
harsh cedar
#

Projectile motion is a form of motion experienced by an object or particle (a projectile) that is projected near the Earth's surface and moves along a curved path under the action of gravity only (in particular, the effects of air resistance are passive and assumed to be negligible). This curved path was shown by Galileo to be a parabola, but ma...

cobalt sphinx
#

You are asking why some other code has a different result than this code I assume and I can't tell what you are doing. You may have drag turned on

harsh cedar
#

in simple terms the angle the gun has to shoot at to reach the target

cobalt sphinx
#

You may have other things influencing the trajectory

harsh cedar
#

all drag is off

cobalt sphinx
#

I gave up trying to read between the lines on what you posted. Narrow it down to a couple lines instead of an entire update function

harsh cedar
#

angleFinished = 2 * Mathf.Acos(angle);

uneven sorrel
#

You set g = **โ€“**Physics.gravity.y, which will make g a positive number. Is that what you want?

harsh cedar
#

will try it without the -

#

yeah, without it everything messes up

uneven sorrel
#

I'm confused by gravity * distance. Gravity works over time, not distance.

harsh cedar
uneven sorrel
#

One way to think about it is that you want velocity.y + (gravity.y * time) to == 0 at half the distance to the target (if the target height is the same as the firing height).

harsh cedar
#

right

uneven sorrel
#

So, any time gd > v^2, the function doesn't work, right? Meaning that there is not enough velocity to ever make it there.

harsh cedar
#

yup, doesn't seem like it cares about that though

uneven sorrel
#

Your arcsin and arccos functions will probably throw an error.

harsh cedar
#

not getting any errors

uneven sorrel
#

Part of what was confusing me is that the variable angle in your code is not actually describing an angle. It's a ratio that is limited to the range [-1..1]. Then you take the arcsin of that ratio to get an angle. This doesn't affect the code at all, but it was confusing.

harsh cedar
#

actually yeah, i am getting an error sometimes, and sorry about that

dusty ferry
#

Hi! I have a script and I dont know how to do that idea.

Now if I exit the vehicle (the vehicle is on the side) the camera rotates to the rotation that the vehicle has.

So the idea is, if I press "e" (exit the vehicle) the camera rotation is resets.

// using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.Vehicles.Car;

public class carManager : MonoBehaviour {

 public Camera carCam;
 public CarUserControl userCtrl;
 
 private bool inVeh;
 private GameObject player;
 void Start()
 {
     userCtrl.enabled = false;
     carCam.enabled = false;
     inVeh = false;
 }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         if (inVeh == true)
         {
             vehicleControl(null);
         }
     }
 }
 public void vehicleControl(GameObject playerObj)
 {
     if (inVeh == false)
     {
         player = playerObj;
         carCam.enabled = true;
         userCtrl.enabled = true;
         player.SetActive(false);
         player.transform.parent = this.transform;
         
         StartCoroutine(Time(true));
     }
     else
     {
         player.SetActive(true);
         carCam.enabled = false;
         userCtrl.enabled = false;
         player.transform.parent = null;
         player = null;
         StartCoroutine(Time(false));
     }
 }
 private IEnumerator Time(bool inVehicle)
 {
     yield return new WaitForSeconds(1);
     inVeh = inVehicle;
 }
uneven sorrel
#

Maybe:

float AngleOfReach(float dist, float grav, float vel) {
  float ratio = (grav*dist)/(vel*vel);
  if (ratio < -1 || ratio > 1) return float.NaN;
  // Not sure about whether that's the right way to write NaN
  float angleSteep = Mathf.Acos(ratio) * 0.5f;
  return angleSteep;
}

(I think you were multiplying by 2 rather than dividing on line 55.)

#

(Sorry, I need to run. I hope it helped.)

harsh cedar
#

will try it, thanks!

#

also i am multiplying by 2 instead of dividing because the angle was too low

uneven sorrel
harsh cedar
#

gotcha

undone coral
harsh cedar
#

there really is

undone coral
#

what is your gameplay objective?

harsh cedar
#

RTS game with lots of explosions

undone coral
#

so why do you need this value

#

are you trying to model an artillery unit with unity physics?

harsh cedar
undone coral
#

is it important that the shell be a Rigidbody

#

or is it like most RTSes

#

where there isn't really physics gameplay

harsh cedar
#

i would really like it to be a rigidbody

undone coral
#

okay

harsh cedar
#

honestly something that just works

undone coral
#

okay

harsh cedar
#

been trying to do this for like a week

undone coral
#

because you'd just transform . position = ... and do a parabola with a kinematic rigidbody

#

you would do a constant xz change and the parabola for the y

cobalt sphinx
harsh cedar
#

i will get slapped for crossposting

cobalt sphinx
#

Should have started there.

harsh cedar
#

true, true

undone coral
#

it's okay

#

i don't think computing an angle makes any sense here

#

you can look at every artillery unit in every RTS game that anyone's ever played, and you won't find that calculation in it

#

why is it important it's a rigidbody?

#

if the answer is "novel gameplay" that's great

harsh cedar
#

how do they do it in those games then? Is it like you described?

undone coral
#

but if it's not... if it's because you just want collisions it's bad

harsh cedar
#

:(

cobalt sphinx
#

You can raycast where something will travel in the current frame without all this stuff.

#

if that raycast hits anything you can say it will explode there.

harsh cedar
#

honestly with the amount of trouble im having i think i will have to do that

cobalt sphinx
#

You should have a start Vector3 and a end Vector3 IMO

harsh cedar
#

๐Ÿ‘

cobalt sphinx
#

Shells don't magically update mid flight to always hit the target. It's a fire and forget kind of mechanic usually.

harsh cedar
#

i am aware :D

cobalt sphinx
#

If you have a start and an end like where you clicked you can more easily make an approximation that looks right.

harsh cedar
#

oh i can imagine

#

but ill have to return to this problem when i decide to do missiles

cobalt sphinx
#

You know it is going up until the halfway mark

harsh cedar
#

that is true

cobalt sphinx
#

then it is going down

#

All you need is the vertical component where it maxes out.

#

Then you know the midpoint

#

and the height

#

Or you can just wait until it has moved past the X/Z midpoint between start and end

harsh cedar
#

i see i see

#

well, thank you both for all the help

hardy sentinel
#

np

#

oops wrong account

vivid prairie
#

Hi. I'm making origin shift scrip, and I get huge performance spike from physics engine when the origin is shifted. Is there a way to fix it? And thats what profiler shows "Physics.SyncColliderTransform" ~ 30ms and "Physics.FetchResults" ~ 14ms.

hardy sentinel
#

disable syncTransforms while your operation is running, then re-enable when it's done

#

should be Physics.autoSyncTransforms or smth

vivid prairie
hardy sentinel
#

yup!

vivid prairie
#

unfortunately its not working ;_;

hardy sentinel
#

is it 2D maybe?

vivid prairie
#

3d

hardy sentinel
#

hm

#

can you give an example of what your origin shifting does?

#

(like, code operations steps, assuming you can't share code)

#

if it's for multiple objects, enable/disable transform sync before and all objects have performed the operation

vivid prairie
#

Im moving sth like root gameobject

private void Update()
    {
        if(new Vector2(cam.position.x, cam.position.z).sqrMagnitude > changeDist * changeDist)
        {
            Physics.autoSyncTransforms = false;
            ShiftAmount -= new Vector3(cam.position.x, 0, cam.position.z);
            Vector3 deltaShift = - new Vector3(cam.position.x, 0, cam.position.z);
            //cam.transform.position -= ShiftAmount;
            transform.position = ShiftAmount;
            onRootChange?.Invoke(ShiftAmount,deltaShift);
            Physics.autoSyncTransforms = true;
        }
    }
``` sth like this
#

nothing fancy

hardy sentinel
#

yea that shouldn't cause any spikes normally, uh..

#

maybe if you disable RB/collider and re-enable after 1 frame, it could go away

#

would that work?

#

I think it's trying to resolve stuff for the position change, and struggling since it may meet different colliders along the way

vivid prairie
#

idk, i think it will try recalculate colliders transforms after enabling colliders anyway, btw. I also have a lot of colliers ๐Ÿ˜…

#

it could be little below 10k

#

and also i have only colliders without rb so its shouldnt be a problem with "self collision"

uneven sorrel
# cobalt sphinx Do a check if the file exists before hand maybe? I'm not too familiiar with Mac...

Just FYI: I did a lot of testing and a lot of forced restarts of my machine. File.WriteAllBytes() was not the culprit. Somehow, calling Graphics.CopyTexture() on macOS causes Unity to hang and freeze the entire machine some time before the next Update() loop is called. I have no idea what is causing it, but it is new, and as far as I can tell, it's unrelated to the macOS file system security.

#

Thank you again for your help and advice.

raw schooner
#

is there any place i could realistically ask about the engine source code? not the c# reference, but the actual source code.
i'm specifically wondering about how s_instanceBehaviourManager works

cobalt sphinx
#

@uneven sorrelWe would need to see the backend code that does that. Before unity I used to use Allegro.cc to do a lot of 2d side scroller games, but keep in mind is a C++ based deal with no where near as much built in functionality as unity has, but it gives you much more flexibility for copying images and the like. You might write a .dll that works on mac OS instead of hanging. It's probably some kind of unhandled NaN, null, or do...while

thick spire
#

Hey guys, I just wanted to ask. I have read that the composition software design pattern is preferred over the inheritance approach. Is this true?

plucky laurel
#

it depends heavily on the context

#

and even within composition over inheritance after the implementation of the composition architecture you can use inheritance (see MonoBehaviour)

pure dock
#

though this does not mean inheritance is bad and can't be used . . .

plucky laurel
#

its a general direction you want to lean into when designing foundation, but on a smaller scale, inheritance will win in usability

uneven sorrel
# cobalt sphinx <@!356503677990731778>We would need to see the backend code that does that. Bef...

Yes. I'm sure you're right. Once I realized it wasn't the file system but something else, I was able to find an old forum post from 2015 that explored the same issue. It seems that it has something to do with macOS being behind in their implementation of OpenGL (or Metal), though it is strange that it worked perfectly fine exactly one year ago.

I re-implemented using GetPixels and SetPixels32, and it makes an image ofโ€ฆwell, at this point somethingโ€ฆwithout crashing. A little tweaking, and I should have it working tonight! Thank you again for the help.

https://forum.unity.com/threads/solved-custom-shader-bug-on-macos-high-sierra.636955/

thick spire
#

so in terms of modularity, composition gives that more in unity because of how unity is designed right?

plucky laurel
#
Selling the idea to management is also a difficult. You need to be able to explain in plain words exactly how this is going to help get the game done faster. Something along the lines of: "Whenever we add new stuff to the game now, it takes a long time to do, and there are lots of bugs. If we do this new component object thing, it will let us add new stuff a lot quicker, and have fewer bugs."
#

Bad coda many bug, bug bad, money lost.

thick spire
#

and easier to debug

plucky laurel
#

to an extent

pure dock
#

it's easier to design your components (scripts), as in, a stacking manner to add/remove functionality, but it is harder to reference properly without relying on dependency . . .

thick spire
plucky laurel
#

bugs can become less obvious, since now you are encountering issues with interactions between independent components, that can only manifest in specific scenarios, you get problems with initialization, lifecycle, design time errors etc etc

pure dock
thick spire
#

but i did hear singletons are not very good to use too

pure dock
#

singletons are fine. the problem is how (new) people over/misuse them . . .

plucky laurel
#

there is no way to establish a completely decoupled system, there is always a coupling point, it can be masked, singular, be some di framework, event bus, ecs system, but its there and it will require a certain composition so that the entities behave as you intend

thick spire
#

or just only one class and thats it

austere jewel
#

What I'd note is that overuse of inheritance hurts, fast. If you work things around inheritance you'll quickly find you need to fight it to get something done, and then things can get really ugly. Learning the limits of these things takes practice sadly

thick spire
pure dock
pure dock
plucky laurel
# thick spire so what your saying is there has to be some level of dependencies between gameob...

what im saying that if something has a meaning, that meaning has to be described. I.e. a projectile may ignore the fact it doesnt have a mesh renderer code wise, but it wont ignore the fact that it lacks a collider, it wont error out, but it will lose its meaning as a projectile. and then you would have to ensure it has a collider. you can delegate that to the designers, relying on them to establish those components for each and every projectile, but then you get another set of even nastier bugs related to human error during data setup.

#

and that in ideal scenario where runtime changes to the components are not required

thick spire
plucky laurel
#

that simply enforces the existence of the component, but yes

thick spire
#

if the gameobject doesnt have the component and it errors out then the designers can get confused as to whats wrong right

#

because they might not have the knowledge of checking the console logs

plucky laurel
#

example, designer adds a collider, all good. He made 20 projectiles, all good. Starts game all good. Later you discover that some colliders are misaligned, wrong layer set, mesh missing etc, and that is not obvious on playtesting at first.

#

nothing throws errors, it just doesnt work as intended

#

and since nothing throws errors, you are not sure what to debug

thick spire
#

so you have to add debug logs and asserts right

plucky laurel
#

its a simple scenario where you can quickly figure out what is wrong, but there are ridiculous cases of that

thick spire
#

right

plucky laurel
#

i had bugs for ui where designers heavily relied on UnityEvents, debugging that is a nightmare

#

but im derailing, its not why i said it initially

pure dock
#

edge cases can be ridiculous and found anywhere. i just found one while writing documentation to explain the use of a class' methods . . .

thick spire
#

i think thats also a way to test edge cases

pure dock
thick spire
pure dock
#

i use it to check that each implementation created works as intended . . .

thick spire
#

like just simple methods right?

#

if a shoot() method on an object runs

pure dock
#

my timer class, e.g., i run a test to ensure it's paused when i suspend the timer, it's running when i resume, it's cancelled when i cancel it, and it's complete when the duration expires . . .

thick spire
#

this is during runtime right

#

cuz there is runtime and editmode

pure dock
#

yes, these are runtime tests . . .

thick spire
#

have you done tests on editmode?

#

like what kind of tests would you use for that?

pure dock
#

i haven't, but mainly for checking your editor extensions since it has access to your editor code . . .

thick spire
#

about writing documentation

#

is it about writing how and why you coded a specific project?

pure dock
#

documentation provides (detailed) information on the class and its public members . . .

pure dock
#

you describe what a class does
you describe what an event sends (its action)
you describe what a field represents
you describe what a property returns
you describe what a methods does . . .

thick spire
#

ohh i see

#

and you put that in a readme on github

pure dock
#

it's a bit more detailed than a comment . . .

plucky laurel
#

painful

#

i feel you

pure dock
#

i'm creating this as if an asset. so i'm doc'ing all the available members. finishing up the readme rn . . .

#

learning (to actively use) git, writing docs, and creating packages for modular use . . .

plucky laurel
#

good effort, still painful to have to write comments in that style

raw schooner
#

visual studio just autocompletes them for you

plucky laurel
#

"do not put the cat into the microwave"

raw schooner
smoky rose
#

idk is this advanced or not, regardless, what's a fast way of knowing if a point X is inside a direction d within a certain angle a, being d the center of that angle, kinda like an FOV situation, here's an image

i thought of checking if the dot products with the sides of the angle are positive but isn't it too much calculation? i'm not familiar enough with unity's tools for this kind of stuff

#

it's 2d btw

plucky laurel
pure dock
#

yes, you can use dot product . . .

plucky laurel
#

also if dot < 0, return

thick spire
#

interesting

plucky laurel
#

@smoky rose however i can see that getting an angle out of dot requires normalization (if i read correctly) which makes it on par with Angle()

#

actually

#

that is exactly what Angle() does

#
        public static float Angle(Vector2 from, Vector2 to)
        {
            float num = Mathf.Sqrt(from.sqrMagnitude * to.sqrMagnitude);
            float result;
            if (num < 1E-15f)
            {
                result = 0f;
            }
            else
            {
                float f = Mathf.Clamp(Vector2.Dot(from, to) / num, -1f, 1f);
                result = Mathf.Acos(f) * 57.29578f;
            }
            return result;
        }
pure dock
#

true, i just looked at my code and i use Angle to check if it's within a fov . . .

smoky rose
#

i'll try with dot and/or angle but i'm thinking that I may have a problem if the angle is bigger than 90

pure dock
#

i also use Vector2.Dot to check if the target is in front or behind first . . .

glacial trench
#

I want to make the walls that would not be visible from the characters perspective hidden, how would i do that?

#

I've tried googling it, but cant seem to get results which match what I am asking

compact ingot
# glacial trench I've tried googling it, but cant seem to get results which match what I am askin...

you need to check all tiles against the two side-planes of the characters view frustrum and cull them if they are outside (i.e. turn their renderer off or overlay them with "fog"). you do that by finding the two direction vectors that are normals of those planes (i.e. directions orthogonal to them), conststruct a plane from them and do a side-check. if any one side-check fails, the tile is outside the frustrum.

fervent parcel
#

Hey guys, trying to compile a DLL in Monodevelop but I get these errors when I use (nameof) and also when i use Lambda expressions

#

Any idea whay?

#

I am using these references:

orchid marsh
flint sage
#

Well if they're using mono develop, that's no surprise

fervent parcel
flint sage
#

It's been deprecated and not suggest for use for 8 years?

fervent parcel
#

MonoDevelop uses unitys Mono-Bleeding-Edge dll which unity uses however VS uses Microsoft Dlls
The Microsoft DLLs, can cause incompatibility problems in some platforms such as (MacOS & Linux). Even if the asset is intended for Editor only use

flint sage
#

Pretty sure that would only happen if you misconfigure your IDE and use unsupported features

raw schooner
#

Yeah those are issues related to an insanely old compiler/C# version

#

the nameof thing you can only really fix but inputting it as an actual string (very bad), the default issue you fix by giving it the type it should default (default(Color))

fervent parcel
#

Thanks guys, I will do more research

raw schooner
#

I wouldn't use default for this though, because I expect the default for Color to be 0, 0, 0, or black

flint sage
#

default (without the braces) is not supported in his version either

raw schooner
#

So if you give it the actual color 0, 0, 0, it won't know if it's that or default

raw schooner